我已经在我的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 });

最佳答案

得到了我的问题的解决方案。只需再添加两个事件并实现逻辑

更新了代码,

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 []在外部范围中定义。

09-11 20:23