JQ网格显示日期与时间,但希望仅与日期分组

时间:2014-09-01 11:46:58

标签: jquery asp.net-mvc jqgrid jqgrid-asp.net

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

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");

1 个答案:

答案 0 :(得分:0)

您可以使用我在the answer中建议的isInTheSameGroupformatDisplayField功能,以及从版本4.5开始的jqGrid中包含的功能(请参阅herehere )。我希望the demo中包含的the answer提供您需要的所有信息。