jquery - jqgrid addRowData gives error t.p.data.push is not a function -
i adding data grid using custom button. in case if data exists in grid, new row added correctly. if grid empty , add new row, gives uncaught typeerror: t.p.data.push not function error @ jqgrid source file. code used add new row below
var rows = $("#" + gridname).getdataids(); $("#" + gridname).jqgrid("addrowdata", rows.length + 1, { id: rows.length + 1},'first'); $("#" + gridname).editrow(rows.length + 1, true);
i using custom nav bar adding , editing grid.
the grid created using following code createjqgrid:function(gridid, columns, griddata){
$("#"+gridid).jqgrid({ datatype: 'local', data: griddata, editurl: 'clientarray', colmodel: columns, loadonce: false, //width: '100%', autowidth: true, shrinktofit:false, height: 250, rownumbers: false, multiselect: true, celledit: true, toppager: true, clonetotop: true, rownum: 10000, pager: "#pager"+gridid, cellsubmit: 'clientarray', ondblclickrow: function(rowid, irow, icol) { //$("#save" + gridid).removeclass("ui-state-disabled"); }, beforeselectrow: function(rowid, e) { return true; }, beforecellselect: function(rowid, e) { return true; }, aftereditcell: function(rowid, cellname, cellvalue, irow, icol) { var celldom = this.rows[irow].cells[icol]; $(celldom).removeclass("ui-state-highlight"); $("#save" + gridid).removeclass("ui-state-disabled"); }, oncellselect: function(rowid, celname, value, irow, icol) { //$("#save" + gridid).removeclass("ui-state-disabled"); return true; }, loadcomplete: function() { } }); $("#"+gridid).navgrid("#pager"+gridid, { clonetotop: true, edit: false, search: false, add: false, del: false, refresh: false, view: false });
after grid created, based on calls, update griddata grid.
toolbar added using
grid.jqgrid('navbuttonadd', '#' + grid[0].id + '_toppager_left', { // "#list_toppager_left" caption: "", title: "add", id: 'add' + gridname, onclickbutton: function() { // perform something... var rows = $("#" + gridname).getdataids(); $("#" + gridname).jqgrid("addrowdata", rows.length + 1, { id: rows.length + 1 },'first'); $("#" + gridname).editrow(rows.length + 1, true); // call whenever save button needs enabled $("#save" + gridname).removeclass("ui-state-disabled"); } });
when grid has data, addrowdata works, when grid empty, gives error
if(t.p.datatype === 'local') { lcdata[t.p.localreader.id] = id; t.p._index[id] = t.p.data.length; t.p.data.push(lcdata); // error comes on line lcdata = {}; }
you assign data
using griddata
. value have griddata
"when grid empty"? should empty array [] , not undefined
or null
.
moreover filling of grid using var rows = $("#" + gridname).getdataids();$("#" + gridname).jqgrid("addrowdata", rows.length + 1, {..},'first');...
bad if in loop , fill grid many rows. in way usage of rows.length + 1
bad choice if rows can deleted , not inserted. recommend use $.jgrid.randid()
function instead generate unique value van used rowid.
Comments
Post a Comment