I have some issue with jqGrid paging. I want create own group and add row data to it. While I add data to grid on the first page its Ok, but if add new group on the next page, I can see exception in Firebug and empty page. I use addJSONData method. The problem is that addJSONData iterate through all groups in Grid and look for their length:
str += "<tr id=\""+hid+"\" role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+"\"><td colspan=\""+colspans+"\">"+icon+$.jgrid.format(grp.groupText[0], gv, grdata[n].length)+"</td></tr>";
But if I have one group on previous page and only sent data of second group with ajax and call addJSONData it throws exception: length of undefined. How can I solve it?
UPDATE: Here is my code:
function addToGrid(group, ids){
var rowNum = jQuery(myGrid).jqGrid('getGridParam', 'rowNum');
data = jQuery.ajax({
url: myUrl,
data: {'group': group, 'rowNum': rowNum, 'ids': ids},
dataType: 'json',
complete: function(jsondata,stat){
if(stat=="success") {
var targetGrid = jQuery(myGrid);
var myjsongrid = eval('('+jsondata.responseText+')');
var rows = myjsongrid.rows;
if(rows.length != 0){
targetGrid[0].addJSONData(myjsongrid);
}
}
}
});
}
And tabl开发者_如何学Goe:
$(myGrid).jqGrid({
url: myUrlTable,
datatype: 'json',
postData: {},
mtype: 'GET',
jsonReader: { repeatitems : false},
colNames: ['Id', 'Group', 'Bytes'],
colModel: [{name:'id', index: 'id', hidden: true},
{name:'group', index: 'group', width: 100},
{name:'bytes', index: 'bytes', width: 60, classes:'gc column-bytes', sortable: false, sorttype:'int', formatter:'integer'}
],
grouping: true,
groupingView: {
groupField : ['group'],
groupText : ['Group: ({1} items)'],
groupOrder: 'asc',
groupDataSorted : true
},
sortable: true,
toppager: true,
hoverrows: true,
altrows: false,
});
Test data from server:
{"total":1,"page":1,"records":1,"rows":[{"group":"abc", "bytes":229447,"id":"7124"}]}
Another records are similar. I added 20 records and then I added next 5 on another page with group bbb. Method addToGrid is called from another grid and with ids and entered group name to input dialog. Then I pass it to server and server returns valid data to fulefill grid. Server returns only data for the last page in my case 5 rows.
Server response:
{"total":2,"page":2,"records":5,"rows":[{"group":"bbb", "bytes":229447,"id":"7155"},
{"group":"bbb", "bytes":229447,"id":"7156"},
{"group":"bbb", "bytes":229447,"id":"7157"},
{"group":"bbb", "bytes":229447,"id":"7158"},
{"group":"bbb", "bytes":229447,"id":"7159"}
]
}
As @unknown user mentioned in this case you should call groupingSetup method before to call addJsonData, but this is not enough in case you have change the grouping and other parameters dynamically.
You will need to set the changed grouped parameters with setGridParam method before to call groupingSetup.
More you can find in our new Guriddo jqGrid documentation
Kind Regards
i also got the same problem.following line would fix the code.
$("#jqGrid").jqGrid("groupingSetup");
add this code before addJSONData function.
function addToGrid(group, ids){
var rowNum = jQuery(myGrid).jqGrid('getGridParam', 'rowNum');
data = jQuery.ajax({
url: myUrl,
data: {'group': group, 'rowNum': rowNum, 'ids': ids},
dataType: 'json',
complete: function(jsondata,stat){
if(stat=="success") {
$("#myGrid").jqGrid("groupingSetup");
var targetGrid = jQuery(myGrid);
var myjsongrid = eval('('+jsondata.responseText+')');
var rows = myjsongrid.rows;
if(rows.length != 0){
targetGrid[0].addJSONData(myjsongrid);
}
}
}
});
精彩评论