我已经在我的asp.net mvc项目中实现了jqgrid并且工作正常,我在排序时遇到问题。在加载我保持groupCollapse = true,我需要它,但当我打开任何组,并在点击排序时它被折叠。是否有任何解决方案可以防止打开组在排序时崩溃。
我的代码
jQuery("#tblEmployeeReport").jqGrid({
data: ParsedJson,
datatype: "local",
height: 'auto',
width: 'auto',
rowNum: 50,
rowList: [50, 100],
colNames: ['Date', 'Clock In', 'Clock Out', 'Working Hr'],
colModel: [
{ name: 'DayDate', index: 'DayDate', width: 90, sorttype: "date", resizable: false, },
{ name: 'ClockIn', index: 'ClockIn', width: 100, resizable: false, },
{ name: 'ClockOut', index: 'ClockOut', width: 100, resizable: false, },
{ name: 'Working_Hr', index: 'Working_Hr', width: 100, resizable: false, },
],
pager: "#EmployeeReportPager",
viewrecords: true,
sortorder: "desc",
caption: "Employee Report",
sortname: 'DayDate',
grouping: true,
resizable: false,
groupingView: {
groupField: ['DayDate'],
groupText: ['<b>{0} - {1} Employee</b>'],
groupCollapse: true,
groupOrder: ['asc']
}
});
jQuery("#tblEmployeeReport").jqGrid('navGrid', '#EmployeeReportPager', { add: false, edit: false, del: false });
答案 0 :(得分:2)
解决了我的问题。只需添加两个事件并实现逻辑
更新代码,
var expandedEmpGroups = [];
jQuery("#tblEmployeeReport").jqGrid({
data: ParsedJson,
datatype: "local",
height: 'auto',
width: 'auto',
rowNum: 50,
rowList: [50, 100],
colNames: ['Date', 'Clock In', 'Clock Out', 'Working Hr'],
colModel: [
{ name: 'DayDate', index: 'DayDate', width: 90, sorttype: "date", resizable: false, },
{ name: 'ClockIn', index: 'ClockIn', width: 100, resizable: false, },
{ name: 'ClockOut', index: 'ClockOut', width: 100, resizable: false, },
{ name: 'Working_Hr', index: 'Working_Hr', width: 100, resizable: false, },
],
pager: "#EmployeeReportPager",
viewrecords: true,
sortorder: "desc",
caption: "Employee Report",
sortname: 'DayDate',
grouping: true,
resizable: false,
groupingView: {
groupField: ['DayDate'],
groupText: ['<b>{0} - {1} Employee</b>'],
groupCollapse: true,
groupOrder: ['asc']
},
onClickGroup: function (hid, collapsed) {
var i;
i = $.inArray(hid, expandedEmpGroups) > -1;
if (!collapsed && i == false) {
expandedEmpGroups.push(hid);
}
else if (collapsed && i == true) {
//Grouphid.splice(i, 1);
expandedEmpGroups.splice($.inArray(hid, expandedEmpGroups), 1);
}
},
loadComplete: function () {
var $this = $(this)
if (expandedEmpGroups.length > 0) {
for (var i = 0; i <= expandedEmpGroups.length; i++) {
if (typeof (expandedEmpGroups[i]) != "undefined") {
$this.jqGrid("groupingToggle", expandedEmpGroups[i]);
}
}
}
}
});
jQuery("#tblEmployeeReport").jqGrid('navGrid', '#EmployeeReportPager', { add: false, edit: false, del: false });
数组变量expandedEmpGroups []在外部作用域中定义。