2014-09-01 38 views
0

你好我在我的Asp.Net MVC应用程序中使用JQ网格。在我的网格中有一个名为InvoiceDate的字段,我必须将它与InvoiceDate进行分组,InvoiceDate随时间而来,并且在网格中,我必须随时间显示日期,但对于分组,我必须将它与仅日期分组即,如果我有3数据JQ网格显示日期与时间,但只想与日期分组

1. 08/29/2014 13:11:56 
2. 08/29/2014 13:12:45 
3. 08/30/2014 12:09:20 

在网格我有显示日期与上述相同,但是,分组我必须只日期组这意味着

2014年8月29日和2014年8月30日,它是可能的,如果是的话请给我解决方案。 我的代码是

jQuery("#ItemSoldReport").jqGrid({ 
         data: ParsedJson, 
         datatype: "local", 
         height: 'auto', 
         width: 'auto', 

         rowNum: 100, 
         rowList: [10, 20, 30, 50, 100], 
         colNames: ['Date', 'UPC', 'Name', 'Department', 'Qty', 'Cost', 'Price', 'Margin'], 
         colModel: [ 
          { name: 'InvoiceDate', index: 'InvoiceDate', width: 90, sorttype: "date", summaryType: 'count', summaryTpl: '({0}) total', resizable: false, formatoptions: { newformat: 'm/d/Y' }, datefmt: "m/d/Y" }, 
          { name: 'Barcode', index: 'Barcode', width: 130, resizable: false, }, 
          { name: 'ItemName', index: 'ItemName', width: 150, resizable: false, }, 
          { name: 'DeptName', index: 'DeptName', width: 120, resizable: false }, 
          { name: 'ItemQuantity', index: 'ItemQuantity', width: 50, align: "right", sorttype: "int", resizable: false, }, 
          { name: 'CostPrice', index: 'CostPrice', width: 80, align: "right", sorttype: 'number', formatter: 'number', summaryType: 'sum', resizable: false, }, 
          { name: 'SalesPrice', index: 'SalesPrice', width: 80, align: "right", sorttype: "number", summaryType: 'sum', formatter: "number", resizable: false, }, 
          { name: 'ExtendedPriceMargin', index: 'ExtendedPriceMargin', width: 50, align: "right", resizable: false, }, 
         ], 
         pager: "#ItemSoldPager", 

         viewrecords: true, 
         sortorder: "desc", 
         caption: "Item Sold Report", 
         //sortname: 'DeptName', 
         grouping: true, 
         hidegrid: false, 
         groupingView: { 
          groupField: ['InvoiceDate'], 
          groupDataSorted: false, 
          groupText: ['<b>{0} - {1} Item(s)</b>'], 
          groupCollapse: true, 
          groupOrder: ['asc'], 
          groupSummary: [true], 

          //groupSorted: false, 
         }, 
         footerrow: true, 
         userDataOnFooter: true, 

         onClickGroup: function (hid, collapsed) { 
          //saveCollapsedStateToLocalStorage(hid, collapsed) 

          var i; 
          i = $.inArray(hid, expandedGroups) > -1; 

          if (!collapsed && i == false) { 
           expandedGroups.push(hid); 
          } 
          else if (collapsed && i == true) { 
           //Grouphid.splice(i, 1); 
           expandedGroups.splice($.inArray(hid, expandedGroups), 1); 
          } 

         }, 

         loadComplete: function() { 
          var $this = $(this), 
           //sum = $this.jqGrid("getCol", "SalesPrice", false, "sum"), 
           $footerRow = $(this.grid.sDiv).find("tr.footrow"), 
           localData = $this.jqGrid("getGridParam", "data"), 
           totalRows = localData.length, 
           totalSum = 0, 
           totalCostSum = 0, 
           $newFooterRow, 
           i; 


          for (i = 0; i < totalRows; i++) { 
           totalSum += parseFloat(localData[i].SalesPrice, 10); 
           totalCostSum += parseFloat(localData[i].CostPrice, 10); 

          } 
          $footerRow.find(">td[aria-describedby=" + this.id + "_InvoiceDate]") 
           .text("Grand Total:"); 
          $footerRow.find(">td[aria-describedby=" + this.id + "_SalesPrice]") 
           .text($.fmatter.util.NumberFormat(totalSum, $.jgrid.formatter.number)); 

          $footerRow.find(">td[aria-describedby=" + this.id + "_CostPrice]") 
          .text($.fmatter.util.NumberFormat(totalCostSum, $.jgrid.formatter.number)); 



          if (expandedGroups.length > 0) { 
           for (var i = 0; i <= expandedGroups.length; i++) { 
            if (typeof (expandedGroups[i]) != "undefined") { 
             $this.jqGrid("groupingToggle", expandedGroups[i]); 
            } 
           } 
          } 

         } 

        }); 
        jQuery("#ItemSoldReport").jqGrid('navGrid', '#ItemSoldPager', { add: false, edit: false, del: false }); 
        jQuery("#ItemSoldReport").setGridWidth("100"); 

回答

0

您可以使用isInTheSameGroupformatDisplayField特点,我在the answer建议和包含在jqGrid的开始4.5版本(见herehere)。我希望the answer中包含的the demo提供您需要的所有信息。

+0

我想在组中应用它,那我该如何应用这个 – 2014-09-01 13:14:50

+0

@AhhijitPandya:你应该在'groupingView'中添加'isInTheSameGroup'和'formatDisplayField'。该代码将非常接近[demo](http://www.ok-soft-gmbh.com/jqGrid/NotExactGrouping1.htm)数组“isInTheSameGroup”中的第二个函数。确切的实现取决于您拥有的输入数据的确切格式(您不包含您使用的'ParsedJson'的测试数据)。 – Oleg 2014-09-01 15:23:47