2014-03-27 24 views
1

我已經在我的asp.net mvc項目中實現了jqgrid,它的工作正常,我在排序時遇到問題。在負載我保持groupCollapse =真,我需要它,但是當我打開任何組,當點擊排序其正在崩潰。有什麼解決方案來防止開放組在排序時被摺疊。如何防止在排序時崩潰jqgrid

我的代碼在這裏

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

得到了我的闕的解決方案。只是增加兩個事件和執行邏輯

更新的代碼,

變種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 []在外部作用域中定義。