I have list of list json using the code and got a proper answer also after i want polling every 6 sec append data from db with same list of list json format its also working fine without subgrid system but am integrating both after i got a parent polling data correct but I am not getting the subgrid data its empty(fetch the data backend for subgrid fine).
Second time UPDATED CODE after Oleg comments I have attached the code please find it
var $grid = $("#list11"),
mainGridPrefix = "s_";
jQuery("#list11").jqGrid({
url: 'server.php?getList',
datatype: "json",
data: firstListJson,
height: 200,
colNames: ['Inv No', 'Date', 'Client'],
colModel: [{
name: 'id',
index: 'id',
width: 55
}, {
name: 'invdate',
index: 'invdate',
width: 90
}, {
name: 'name',
index: 'name',
width: 100
}],
rowNum: 10,
gridview: true,
rowList: [10, 20, 30],
pager: '#pager11',
loadonce: false,
sortname: 'id',
viewrecords: true,
idPrefix: mainGridPrefix,
sortorder: "desc",
multiselect: false,
caption: "Subgrid With polling",
jsonReader: {
repeatitems: false,
id: 'id'
},
beforeProcessing: function(data) {
var rows = data,
l = data.length,
i, item, subgrids = {};
for (i = 0; i < l; i++) {
item = rows[i];
if (item.subGridData) {
subgrids[item.id] = item.subGridData;
}
}
//alert(subgrids);
data.userdata = subgrids;
},
subGrid: true,
subGridRowExpanded: function(subgridDivId, rowId) {
var subGridID = $("#" + subgridDivId + "_t");
var $subgrid = $("<table id='" + subgridDivId + "_t'></table>"),
pureRowId = $.jgrid.stripPref(mainGridPrefix, rowId),
subgrids = $(this).jqGrid("getGridParam", "userData");
$subgrid.appendTo("#" + $.jgrid.jqID(subgridDivId));
$subgrid.jqGrid({
datatype: "local",
data: subgrids[pureRowId],
colNames: ['Emp ID', 'Name', 'Age'],
colModel: [{
name: 'id',
index: 'id',
width: 55
}, {
name: 'name',
index: 'name',
width: 90
}, {
name: 'age',
index: 'age',
width: 100
}],
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'id',
viewrecords: true,
sortorder: "desc",
multiselect: false
});
}
});
jQuery("#list11").jqGrid('navGrid', '#pager11', {
add: false,
edit: false,
del: false
});
Below code
for json list of list
var firstListJson = [{
"id": "01",
"invdate": "2014-07-24",
"name": "John",
"subGridData": [{
"id": "01",
"name": "Krishna",
"age": "28"
}, {
"id": "01",
"name": "Jai",
"age": "28"
}, {
"id": "01",
"name": "Suresh",
"age": "28"
}]
}, {
"id": "02",
"invdate": "2014-07-24",
"name": "Hill",
"subGridData": [{
"id": "01",
"name": "Mani",
"age": "28"
}, {
"id": "01",
"name": "Raj",
"age": "28"
}, {
"id": "01",
"name": "Main",
"age": "28"
}]
}];
Below code
for polling code
function pollData() {
var pollingListUrl = 'server.php?getPollList';
$.ajax({
type: "POST",
url: pollingListUrl,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function(data) {
var $mygrid = $("#list11");
$mygrid.jqGrid("addRowData", "id", data);
$mygrid.trigger("reloadGrid", [{
current: true
}]);
},
error: function(x, e) {
alert("error occur");
}
});
}