x11 Posted December 15, 2020 Share Posted December 15, 2020 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! Quote Link to comment Share on other sites More sharing options...
x11 Posted December 16, 2020 Author Share Posted December 16, 2020 maybe column names can be used in xtemplate? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 16, 2020 Share Posted December 16, 2020 On 12/15/2020 at 7:31 PM, x11 said: Tell me please, what is the correct way to substitute variables or constants for specific numbers? Hello, Please clarify your question again. Quote Link to comment Share on other sites More sharing options...
x11 Posted December 17, 2020 Author Share Posted December 17, 2020 i want use field name '<td colspan="2">Ціна {price}</td>' not index '<td colspan="2">Ціна {8}</td>' Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 17, 2020 Share Posted December 17, 2020 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; Quote Link to comment Share on other sites More sharing options...
x11 Posted December 17, 2020 Author Share Posted December 17, 2020 А если скрипт находится в файле? А файл загружается при создании формы... procedure TfmmFindPhone.UnimFormCreate(Sender: TObject); begin dbgLoadJsUniEvents(dbgResult, constBeforInit);// XTamplate fmmFindPhone.dbgResult.beforeInit.js end; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 17, 2020 Share Posted December 17, 2020 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)]; } } ); } 1 Quote Link to comment Share on other sites More sharing options...
x11 Posted December 17, 2020 Author Share Posted December 17, 2020 -- Quote Link to comment Share on other sites More sharing options...
x11 Posted December 17, 2020 Author Share Posted December 17, 2020 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)]; } Quote Link to comment Share on other sites More sharing options...
x11 Posted December 17, 2020 Author Share Posted December 17, 2020 console.log(sender.fieldsNames); undefined Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 17, 2020 Share Posted December 17, 2020 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; ? Quote Link to comment Share on other sites More sharing options...
x11 Posted December 17, 2020 Author Share Posted December 17, 2020 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; Quote Link to comment Share on other sites More sharing options...
x11 Posted December 17, 2020 Author Share Posted December 17, 2020 -- Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 17, 2020 Share Posted December 17, 2020 1 minute ago, x11 said: JSInterface.JSAssign('fieldsNames', [JSInterface.JSStatement(Cols)]); You are missing with UnimDBListGrid1 do 1 Quote Link to comment Share on other sites More sharing options...
x11 Posted December 17, 2020 Author Share Posted December 17, 2020 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 Quote Link to comment Share on other sites More sharing options...
x11 Posted December 17, 2020 Author Share Posted December 17, 2020 SORRY "ID" not 'id' Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 17, 2020 Share Posted December 17, 2020 3 minutes ago, x11 said: SORRY "ID" not 'id' So, does it work for you? Quote Link to comment Share on other sites More sharing options...
x11 Posted December 17, 2020 Author Share Posted December 17, 2020 Yes. Thank you very much! 1 Quote Link to comment Share on other sites More sharing options...
x11 Posted January 22, 2021 Author Share Posted January 22, 2021 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. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 22, 2021 Share Posted January 22, 2021 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? Quote Link to comment Share on other sites More sharing options...
x11 Posted January 22, 2021 Author Share Posted January 22, 2021 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); 1 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 22, 2021 Share Posted January 22, 2021 4 minutes ago, x11 said: I found on the forum Did this code help you? Quote Link to comment Share on other sites More sharing options...
x11 Posted January 22, 2021 Author Share Posted January 22, 2021 Yes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.