【问题标题】:JQ grid display date with time but want grouping with only dateJQgrid 显示日期和时间,但只需要日期分组
【发布时间】:2014-09-01 11:46:57
【问题描述】:

你好,我在我的 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

在网格中我必须显示与上面相同的日期,但在分组时我必须只用日期表示分组

08/29/2014 和 08/30/2014 ,是否可能,如果是,请给我解决方案。 我的代码是

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 我想在群里申请,那我怎么申请
    • @AbhijitPandya:您应该在groupingView 中添加isInTheSameGroupformatDisplayField。该代码将非常接近the demo 的数组isInTheSameGroup 中的第二个函数。确切的实现取决于您拥有的输入数据的确切格式(您不包括您使用的ParsedJson 的测试数据)。
    猜你喜欢
    • 2015-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 2022-01-03
    • 1970-01-01
    • 2012-11-18
    相关资源
    最近更新 更多