我试图使用 jQGrid 构建一个子网格来显示父子关系。我关注经理和员工的关系。我正在服务器上构建一个 JSON,这就是它的外观
{"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"}]}]
问题是当我单击展开时,我从本地存储的employeeLocalJSON 变量中查找数据并将集合分配给子网格。但它没有显示在子网格中。我不知道为什么会这样。我想从服务器加载 json 并显示我应该使用相同的子网格,所以我将它存储在本地变量 employeeLocalJSON 中。
这是我的 jQGrid 代码
$(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 });
});
如何实现从单个 JSON 加载子网格?我的代码可能有什么问题?我无法看到子网格,即使我绑定了数据