jQWidgets Forums
jQuery UI Widgets › Forums › Grid › addrow problem
Tagged: grid
This topic contains 19 replies, has 2 voices, and was last updated by damc 12 years, 4 months ago.
-
Authoraddrow problem Posts
-
Hi,
I migrate from version 2.4.2 to new version 2.6.1.
I have a problem with addrow function. Code works with version 2.4.2 jQWidgest, in version 2.6.1 does not work.I have noticed that parameter rowid is undefined in version 2.6.1 if I passes null. (From documentation: // @param row id. Pass null, if you want the new id to be auto-generated or pass a row id).
And parameter rowdata does not have properties uid and undefined in new version.I look the demo createremoveupdatedata and like in mine application the rowid is undefined and rowdata does not have properties uid and undefined.
Thank you for your help.
Hi damc,
Please, check the demo’s implementation. It works as expected. I also suggest you to take a look at the Release History, before updating to newer versions.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
I have read the Release History (I noticed the new parameter (commit) in addrow function) and I have checked my code, but I don’t find solution for my problem.
I debugged demo createremoveupdatedata with firebug and noticed, that rowid parameter is undefined. Is this OK?
Thank you for your help.
Hi damc,
In our sample, we do not pass an id when the “addrow” method is called.
Example:
var commit = $("#jqxgrid").jqxGrid('addrow', null, datarow);
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
For rowid parameter we put null, same like it is in demo.
In documentation (look jqxGrid API, addrow) it say’s that if you want the new id to be auto-generated, pass null. If I debug my code with version 2.4.2 widgets, I see parameter rowid (for first added row it is 0, for second it is 1, and so forward…).
But in version 2.6.1 is rowid undefined, same like in demo. What could be wrong?
Thank you for your help.
Hi damc,
How do you see the parameter? Would you like to post a code which demonstrates your scenario?
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
You can debug code in createremoveupdatedata demo add new row button, look at rowid in addrow: function (rowid, rowdata, position, commit) {…}.
Thank you for your help.
Hi damc,
According to me, it works as expected. When a new row is added and the “rowid” is null, the new row’s id is auto-generated.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
I have send to support@jqwidgets.com a print screen where it is with yellow color marked what I mean. In version 2.4.2 was rowid = 10 in this case. Here it is undefined. Is this OK or I miss something?
Thank you for your help.
Hi Peter,
I can’t fix my code for adding a row in jqGrid to work with new version of jqWidgets. Below is code that works with 2.4.2. Can you help me to find problems?
this.loadData = function () { source = { localdata: self.myData.arrayA, datatype: 'local', addrow : function (rowid, rowdata) { var observableArray = self.myData.arrayA, record = null; observableArray.push({ dateFrom: null, dateTo: null, duration: null, text: null, code: null, currency: null }); record = observableArray()[rowid]; for (var obj in record) { record[obj] = ko.observable(record[obj]); } ko.mapping.fromJS(observableArray(), {}, self.myData.arrayA()); }, deleterow : function (rowid) { var observableArray = self.myData.arrayA; observableArray.remove(observableArray()[rowid]); }, updaterow : function(rowid, rowdata) { var observableArray = self.myData.arrayA, record = null; observableArray.replace(observableArray()[rowid], rowdata); record = self.myData.arrayA()[rowid]; for (var obj in record) { record[obj] = ko.observable(rowdata[obj]); } }; dataAdapter = new jQuery.jqx.dataAdapter(source); // grid $('#jqxgrid').jqxGrid({ width: 885, source: dataAdapter, pageable: true, autoheight: true, editable: true, selectionmode: 'singlecell', pagesize: 5, pagesizeoptions: ['5', '10'], columns: [{ text: 'Date from', datafield: 'dateFrom', width: 110, columntype: 'datetimeinput', cellsformat: 'dd.MM.yyyy', initeditor: function (row, cellvalue, editor) { } }, { text: 'Date to', datafield: 'dateTo', width: 110, columntype: 'datetimeinput' }, { text: 'Duration', datafield: 'duration', width: 120 }, { text: 'Some text', datafield: 'text', width: 140 }, { text: 'Code', datafield: 'code', width: 90, cellsalign: 'right' }, { text: 'Currency', datafield: 'currency', width: 170, cellsalign: 'right' }] });}; this.addRow_X = function() { var datarow = {}, paginginformation = null, pagescount = -1; $('#jqxgrid').jqxGrid('addrow', null, datarow); paginginformation = $('#jqxgrid').jqxGrid('getpaginginformation'); pagescount = paginginformation.pagescount; $('#jqxgrid').jqxGrid('gotopage', pagescount);};
Thanks for your help.
Hi Peter,
I’m still struggling with my jqGrid add row functionality. Peter did you find solution or any problem why my code posted above doesn’t work?
Thank you for your help.
Hi damc,
As far as I see from your code, you use the “rowid” param for getting the last record from an observableArray. You can simply use this:
record = observableArray()[observableArray().length - 1];
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comNi Peter,
I have changed my code and found some problems:
1. If It is empty table and I’m calling addrow than items in added row are not an observable in an observableArray – not OK.
2. If there are data loaded in table and I’m calling addrow than items in added row is an observable in an observableArray – it’s OK.
3.I have problems with editing if I add empty row and use null for values -> var datarow = { dateFrom: null, dateTo: null, duration: null, text: null, code: null, currency: null }. Look code below I put empty String.My Code:
this.loadData = function () { source = { localdata: self.myData.arrayA, datatype: 'local', addrow: function (rowid, rowdata, position, commit) { // synchronize with the server - send insert command // call commit with parameter true if the synchronization with the server is successful //and with parameter false if the synchronization failed. commit(true); }, deleterow: function (rowid, commit) { // synchronize with the server - send delete command // call commit with parameter true if the synchronization with the server is successful //and with parameter false if the synchronization failed. commit(true); }, updaterow : function(rowid, rowdata, commit) { commit(true); } }; dataAdapter = new jQuery.jqx.dataAdapter(source); // grid $('#jqxgrid').jqxGrid({ width: 885, source: dataAdapter, pageable: true, autoheight: true, editable: true, selectionmode: 'singlecell', pagesize: 5, pagesizeoptions: ['5', '10'], columns: [{ text: 'Date from', datafield: 'dateFrom', width: 110, columntype: 'datetimeinput', cellsformat: 'dd.MM.yyyy', initeditor: function (row, cellvalue, editor) { } }, { text: 'Date to', datafield: 'dateTo', width: 110, columntype: 'datetimeinput' }, { text: 'Duration', datafield: 'duration', width: 120 }, { text: 'Some text', datafield: 'text', width: 140 }, { text: 'Code', datafield: 'code', width: 90, cellsalign: 'right' }, { text: 'Currency', datafield: 'currency', width: 170, cellsalign: 'right' }] });}; this.addRow_X = function() { var datarow = { dateFrom: '', dateTo: '', duration: '', text: '', code: '', currency: '' }; var commit = $('#jqxgrid').jqxGrid('addrow', null, datarow);};
Thank you for your help.
Hi Peter,
I have changed my code and found some problems:
1. If It is empty table and I’m calling addrow than items in added row are not an observable in an observableArray – not OK.
2. If there are data loaded in table and I’m calling addrow than items in added row is an observable in an observableArray – it’s OK.
3.I have problems with editing if I add empty row and use null for values -> var datarow = { dateFrom: null, dateTo: null, duration: null, text: null, code: null, currency: null }. Look code below I put empty String.My Code:
this.loadData = function () { source = { localdata: self.myData.arrayA, datatype: 'local', addrow: function (rowid, rowdata, position, commit) { // synchronize with the server - send insert command // call commit with parameter true if the synchronization with the server is successful //and with parameter false if the synchronization failed. commit(true); }, deleterow: function (rowid, commit) { // synchronize with the server - send delete command // call commit with parameter true if the synchronization with the server is successful //and with parameter false if the synchronization failed. commit(true); }, updaterow : function(rowid, rowdata, commit) { commit(true); } }; dataAdapter = new jQuery.jqx.dataAdapter(source); // grid $('#jqxgrid').jqxGrid({ width: 885, source: dataAdapter, pageable: true, autoheight: true, editable: true, selectionmode: 'singlecell', pagesize: 5, pagesizeoptions: ['5', '10'], columns: [{ text: 'Date from', datafield: 'dateFrom', width: 110, columntype: 'datetimeinput', cellsformat: 'dd.MM.yyyy', initeditor: function (row, cellvalue, editor) { } }, { text: 'Date to', datafield: 'dateTo', width: 110, columntype: 'datetimeinput' }, { text: 'Duration', datafield: 'duration', width: 120 }, { text: 'Some text', datafield: 'text', width: 140 }, { text: 'Code', datafield: 'code', width: 90, cellsalign: 'right' }, { text: 'Currency', datafield: 'currency', width: 170, cellsalign: 'right' }] });}; this.addRow_X = function() { var datarow = { dateFrom: '', dateTo: '', duration: '', text: '', code: '', currency: '' }; var commit = $('#jqxgrid').jqxGrid('addrow', null, datarow);};
Thank you for your help.
Hi Peter,
did you manage to find a solution to the problems that I have described (adding rows if we have an empty jqxGridit – items are not observable and how to add an empty row – problems with null)?
Thank you.
-
AuthorPosts
You must be logged in to reply to this topic.