Jump to content

named params in xtemplate (TUnimDBListGrid)


x11

Recommended Posts

Tell me please, what is the correct way to substitute variables or constants for specific numbers?

 

function beforeInit(sender, config){
	config.loadMask = false;
	config.loadingText = 'загрузка...';
	config.emptyText = 'даних немає'; 
	config.grouped = false;
	var id 		 	= 0;
	var idType 	 	= 25;
	var price 	 	= 8;

	var descr = '<table class="tblResDescr">' +
                    '<tr>' +
						'<td class="tdDbgRowID">ID {id}</td>' +
							'<td class="tdBtnPopup"><button class="btnPopup" data-id="{id}" type-id="{idType}"><i class="fas fa-angle-down"></i></td>' +
						'</tr>' +                     
                    '<tr>' +
                        '<td colspan="2">Ціна {price}</td>' +
                    '</tr>' +                   
                    '<tr>' +

Thanx a lot!

Link to comment
Share on other sites

41 minutes ago, x11 said:

not index


'<td colspan="2">Ціна {8}</td>'

What if you will use

Form -> OnCreate event:

procedure TMainmForm.UnimFormCreate(Sender: TObject);
begin
  ...
  '<td colspan="2">Ціна {'+ UnimDBListGrid1.ColumnByName(fieldname).Index.ToString +'}</td>'
  ...
end;

 

Link to comment
Share on other sites

А если скрипт находится в файле?

А файл загружается при создании формы...

 

procedure TfmmFindPhone.UnimFormCreate(Sender: TObject);
begin
  dbgLoadJsUniEvents(dbgResult, constBeforInit);// XTamplate fmmFindPhone.dbgResult.beforeInit.js
end;

 

Link to comment
Share on other sites

1 hour ago, x11 said:

А если скрипт находится в файле?

А файл загружается при создании формы...

One possible solution

1. 

procedure TMainmForm.UnimFormCreate(Sender: TObject);
var
  Cols: string;
  I: Byte;
begin
  with UnimDBListGrid1 do
  begin
    for I := 0 to Columns.Count-1 do
      Cols :=  Cols + '"' + Columns[I].FieldName + '",';

    Cols := '[' + Cols + ']';
    JSInterface.JSAssign('fieldsNames', [JSInterface.JSStatement(Cols)]);
  end;

end;

2. 

function beforeInit(sender, config)
{
    config.itemTpl = new Ext.XTemplate(
        '<table>' +
        '  <tr>' + 
        '    <td style="padding-top:3px;">{[this.getVal(values, "Length (cm)")]}</td>' +
        '  </tr>' +
        '</table>', {
            getVal: function(val, fieldName) {
                return val[sender.fieldsNames.indexOf(fieldName)];
            }
        }
    );
}

 

  • Like 1
Link to comment
Share on other sites

Only the first line is visible in the log

getVal: function(val, fieldName) {
		console.log(fieldName);
		console.log(val[sender.fieldsNames.indexOf(fieldName)]);
		return val[sender.fieldsNames.indexOf(fieldName)];
}

 

Screenshot_9.jpg

Link to comment
Share on other sites

6 minutes ago, x11 said:

console.log(sender.fieldsNames);

 

 

1 hour ago, Sherzod said:

procedure TMainmForm.UnimFormCreate(Sender: TObject); var Cols: string; I: Byte; begin with UnimDBListGrid1 do begin for I := 0 to Columns.Count-1 do Cols := Cols + '"' + Columns[I].FieldName + '",'; Cols := '[' + Cols + ']'; JSInterface.JSAssign('fieldsNames', [JSInterface.JSStatement(Cols)]); end; end;

?

Link to comment
Share on other sites

procedure TfmmFindPhone.UnimFormCreate(Sender: TObject);
begin
  SetFieldsToJS(dbgResult);
  dbgLoadJsUniEvents(dbgResult, constBeforInit);// загручка XTamplate fmmFindPhone.dbgResult.beforeInit.js
end;

procedure TfmmFindPhone.SetFieldsToJS(dbg: TUnimDBListGrid);
var
 cols: string;
 i: byte;
begin
  for I := 0 to pred(dbg.Columns.Count) do
    Cols :=  Cols + '"' + dbg.Columns[I].FieldName + '",';

  Cols := '[' + Cols + ']';
  JSInterface.JSAssign('fieldsNames', [JSInterface.JSStatement(Cols)]);
  
end;

 

Link to comment
Share on other sites

no error and no result

console.log(sender.fieldsNames) return all 28 colums (picture 2)

 

function beforeInit(sender, config){
	config.loadMask = false;
	config.loadingText = 'загрузка...';
	config.emptyText = 'даних немає'; 
	config.grouped = false;
	var descr = '<table class="tblResDescr">' +
                    '<tr>' +
						'<td class="tdDbgRowID">ID {[this.getVal(values, "id")]}</td>' +
...
...

getVal: function(val, fieldName) {
						console.log(fieldName);
						console.log(val[sender.fieldsNames.indexOf(fieldName)]);
						return val[sender.fieldsNames.indexOf(fieldName)];
					}

console.log(val[sender.fieldsNames.indexOf(fieldName)]); return undefined

Screenshot_13.jpg

Screenshot_14.jpg

Link to comment
Share on other sites

  • 1 month later...

Can you please tell me how to scroll through the list (table)?

 

DataSet1.Locate('ID', id, []);

not work with unimDBListGrid with XTamplate :(

The row in the list is highlighted in yellow as focused, but there is no scrolling to selected row.

Link to comment
Share on other sites

27 minutes ago, x11 said:

Can you please tell me how to scroll through the list (table)?

 


DataSet1.Locate('ID', id, []);

not work with unimDBListGrid with XTamplate :(

The row in the list is highlighted in yellow as focused, but there is no scrolling to selected row.

Do you have a test case to check?

Link to comment
Share on other sites

I found on the forum

funcEnsureVisible = 'Ext.defer(function(){'#1'.ensureVisible('#1'.getSelections()[0])}, 200);';
...
...
...
if id > 0 then
  if qUsers.Locate('ID', id, []) then
    dbgUsers.JSInterface.JSCode(funcEnsureVisible);

 

  • Upvote 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...