jQWidgets Forums
jQuery UI Widgets › Forums › Grid › JSON grid addRow not working
This topic contains 3 replies, has 2 voices, and was last updated by Peter Stoev 11 years, 10 months ago.
-
Author
-
I have a grid which is configured with the following source:
var source = { datatype : "json", datafields : [ { name : 'id', map : '@id', type : 'int'}, { name : 'processState', map : 'activity>processState', type : 'string'}, { name : 'clearingHouse', map : 'activity>clearingHouse', type : 'string'}, { name : 'partyAliasName', map : 'trade>party>0>partyAlias>1>partyAliasName', type : 'string' }, { name : 'partyAliasId', map : 'trade>party>0>partyAlias>1>partyAliasId', type : 'int'}, { name : 'transactionReference', map : 'trade>transactionAlias>0>transactionReference',type : 'string'}, { name : 'transactionType', map : 'trade>transactionType', type : 'string'}, { name : 'productType', map : 'trade>product>productType', type : 'string'}, { name : 'tradeDate', map : 'trade>tradeDate', type : 'date' }, { name : 'reference', type : 'string'} ], root : "StyleML", url : "/styleweb/simplex/initialise/cache", // get the data via simplex // (would be called once) data : { style : "full" }, pager : function(pagenum, pagesize, oldpagenum) { // callback called when a page or page size is changed. }, pagesize : 200, updaterow : function(rowid, rowdata, commit) { // synchronize with the server - send update command // call commit with parameter true if the synchronization with the // server is successful // and with parameter false if the synchronization failed. commit(true); }, addrow: function (rowid, commit) { // synchronize with the server - send insert command // call commit with parameter true if the synchronization with the server was successful. // and with parameter false if the synchronization has failed. // you can pass additional argument to the commit callback which represents the new ID if it is generated from a Database. Example: commit(true, idInDB) where "idInDB" is the row's ID in the Database. console.log('Add row called in grid for ' + rowid); commit(true); } };
That works fine. But when I wish to manually insert a new row using:
var commit = $('#jqxgrid').jqxGrid('addrow', null, json);
Nothing happens but the return is
false
– the json is financial data which I can’t show but its exactly the same that is sent from the server which originally populates the gird. No error is given. I just see nothing in the grid.
The grid configuration is as follows:
$scope.grid = $("#jqxgrid").jqxGrid({ width : 1015, height : 800, source : dataAdapter, theme : theme, pageable : true, sortable : true, filterable : true, showfilterrow: true, autosavestate: false, altrows: true, groupable: true, columnsresize : true, columnsreorder: true, pagesizeoptions : [ '20', '100', '1000' ], columns : [ {text : 'ID', datafield : 'id', width : 200, pinned: false, filtertype: 'number'}, {text : 'State', datafield : 'processState', width : 150, cellclassname: cellclassname, filtertype: 'checkedlist'}, {text : 'Clearing House', datafield : 'clearingHouse', width : 200, filtertype: 'checkedlist'}, {text : 'Party Alias', datafield : 'partyAliasName', width : 200, filtertype: 'textbox', filtercondition: 'starts_with'}, {text : 'Party Alias ID', datafield : 'partyAliasId', width : 200, filtertype: 'number'}, {text : 'Tran Ref', datafield : 'transactionReference', width : 200, filtertype: 'textbox', filtercondition: 'starts_with'}, {text : 'Tran Type', datafield : 'transactionType', width : 200, filtertype: 'checkedlist'}, {text : 'Product Type', datafield : 'productType', width : 200, filtertype: 'checkedlist'}, {text : 'Trade Date', datafield : 'tradeDate', width : 200, filtertype: 'textbox', filtercondition: 'starts_with'}, {text : 'Reference', datafield : 'reference', width : 200, filtertype: 'textbox', filtercondition: 'starts_with'} ] });
As always all help appreciated – we are currently in the process of obtaining a license with you guys for my Investment Banking client to move these type of questions off the forum.
Thanks,
Jez
Hi,
Could you let me know what is “json” in your code:
var commit = $('#jqxgrid').jqxGrid('addrow', null, json);
The expected format of the new row should be: {id: 1, processState: “state”}, etc. Also make sure that you add a new row after the Grid’s data is loaded i.e in a “bindingcomplete” event handler or in the Grid’s “ready” callback function.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comOk, got it. But…
The row data in the grid is subtly different from the data. So, in the data I may have:
{a:1, b:2, c[x:1, y:1]} which means the grid needs to be told: (DATA FORMAT 1)
a, b, c>x, y>x
But when I add to the grid I only add the denormalised view, i.e.
{a:1, b:2, x:1, y:1} (DATA FORMAT 2)
So, is there a transformation step i can use (the same as the grid uses) to transform DATA FORMAT 1 to DATA FORMAT 2?
Thanks
Hi,
There is no such built-in transformation step. The new Row should be in the same format as the rows loaded in the Grid. Otherwise, the Grid will not be able to render your new row(s).
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.