jQWidgets Forums
jQuery UI Widgets › Forums › Grid › how to set composite Key to id attribute in grid source?
Tagged: #jqwidgets-grid, grid, javascript grid, jquery grid
This topic contains 1 reply, has 2 voices, and was last updated by Hristo 6 years, 6 months ago.
-
Author
-
Hi,
I have a table with composite Key.
the composite Key are [MyNo] and [MySeq].var source = { datafields: [ { name: 'MyNo', type: 'string' }, { name: 'MySeq', type: 'int' }, { name: 'ColorNo1', type: 'string' }, { name: 'ColorNo2', type: 'string' }, { name: 'ColorNo3', type: 'string' }, { name: 'ColorNo4', type: 'string' }, { name: 'ColorNo5', type: 'string' } ], id: 'MyNo' }
how to set more than two field to id attribute in source?
Hello stanley,
You could use the
beforeprocessing
callback in the DataAdapter’s source.
In the same case, you could usebeforeLoadComplete
callback.
Please, take a look at this source code:var source = { localdata: data, datafields: [ { name: 'myfield' }, { name: 'firstname', type: 'string' }, { name: 'lastname', type: 'string' }, { name: 'productname', type: 'string' }, { name: 'date', type: 'date' }, { name: 'quantity', type: 'number' }, { name: 'price', type: 'number' }, { name: 'uniq', type: 'string' } ], datatype: "array", beforeprocessing: function (data) { for (var i = 0; i < data.length; i++) { var item = data[i]; data[i]["uniq"] = item.id + item.firstname + item.lastname; } return data; }, id: 'uniq' }; var dataAdapter = new $.jqx.dataAdapter(source, { beforeLoadComplete: (records) => { for (var i = 0; i < records.length; i += 1) { var rec = records[i]; rec.myfield = i + 1; } return records; } });
Also, you could use the
uniqueid
that is automatically generated from the DataAdapter.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.