I was trying to build a subgrid using jQGrid to show parent child relationship. I followed Manager and Employee relationships. I am building a JSON at server and this is how it looks
{"total":1,"page":1,"records":20,
"rows":[{"id":"Mgr 001","EmpId":"Mgr 001","Manager Name":"Murali","Dept":"D1"
,"Employees":[{"EmpId":"Emp 100","Name":"Alex","Dept":"Infrastucture"}]}]
The problem is when i click on expand i am finding the data from locally stored employeeLocalJSON variable and assigning the collection to subgrid. But it was not shown in subgrid. I have no idea why it is so. I want to load json from server and to show subgrid i should use the same, so i stored that one in local variable employeeLocalJSON.
I followed jqgrid subgrids from a single nested json
jqGrid Subgrid with "local" Data
JqGrid with subgrid and single XML file as input
Here is my jQGrid code
$(function() {
var employeeLocalJSON;
jQuery("#list").jqGrid({
//start
url: '/Employee/Search',
datatype: "json",
postData: {
searchModel: function () {
var result = {}, i, item,
formInfo = $('#search-form').serializeArray(),
l = formInfo.length;
for (i = 0; i < l; i++) {
item = formInfo[i];
result[item.name] = item.value;
}
return JSON.stringify(result);
}
},
mtype: "POST",
colNames: ['id', 'EmpId', 'Manager Name', 'Dept'],
colModel: [
{ name: 'id', index: 'id', hidden: true, width: 1, align: 'left', key: true },
{ name: 'EmpId', index: 'EmpId', search: true, width: 260, align: 'left' },
{ name: 'ManagerName', index: 'ManagerName', search: false, width: 110, align: 'left' },
{ name: 'Dept', index: 'Dept', search: true, width: 54, align: 'left' }],
pager: $("#pager"),
rowNum: 20,
rowList: [5, 10, 20, 50],
sortname: 'EmpId',
sortorder: "asc",
viewrecords: true,
loadonce: true,
sortable: true,
jsonReader: {
repeatitems: false
},
loadComplete: function (data) {
if (data.rows) {
employeeLocalJSON = data.rows; // save original JSON data
}
},
caption: 'Employee Manager Detail',
subGrid: true,
subGridOptions: {
"plusicon": "ui-icon-triangle-1-e",
"minusicon": "ui-icon-triangle-1-s",
"openicon": "ui-icon-arrowreturn-1-e",
"reloadOnExpand": false,
"selectOnExpand": true
},
subGridRowExpanded: function (grid_id, row_id) {
// //start of subgrid row expanded
var subgrid_table_id, pager_id;
subgrid_table_id = grid_id + "_tone";
pager_id = "pone_" + subgrid_table_id;
$("#" + grid_id).html("<table id='" + subgrid_table_id + "' class='scroll' style='width:100%'></table><div id='" + pager_id + "' class='scroll'></div>");
var indexes = $(this).jqGrid('getGridParam', '_index');
var empList = employeeLocalJSON[indexes[row_id]].Employees;
$("#" + subgrid_table_id).jqGrid({
datatype: 'local',
data: empList,
colNames: ['EmpId', 'Name', 'Dept'],
colModel: [
{ name: 'EmpId', width: 170 },
{ name: 'Name', width: 110 },
{ name: 'Dept', width: 60 }
],
sortname: 'EmpId',
viewrecords: true,
sortorder: "asc",
width: 960
});
}
//end
});
// });
jQuery("#list").jqGrid('navGrid', '#pager', { add: false, edit: false, del: false });
});
How do i achieve loading sub grid from a single JSON? What could be wrong in my code? I am not able to see the subgrid, even i bound a data