0

hello i am using JQ grid in my Asp.Net MVC application. there is a field named InvoiceDate in my grid and i have to group it with InvoiceDate, InvoiceDate is coming with Time and in grid I have to display date with time but for grouping i have to group it with only date i.e if i have 3 data

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

in grid i have to display date same as above but on grouping i have to group it with only date means

08/29/2014 and 08/30/2014 , Is it possible, if yes then please give me solution. My code is

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");
Abhijit Pandya
  • 705
  • 2
  • 12
  • 33

1 Answers1

0

You can use isInTheSameGroup and formatDisplayField features which I suggested in the answer and which are included in jqGrid starting with version 4.5 (see here and here). I hope that the demo included in the answer provides all information which you need.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • i want to apply it in the group , then how can i apply this – Abhijit Pandya Sep 01 '14 at 13:14
  • @AbhijitPandya: You should add `isInTheSameGroup` and `formatDisplayField` in `groupingView`. The code will be very close to the second function from the array `isInTheSameGroup` of [the demo](http://www.ok-soft-gmbh.com/jqGrid/NotExactGrouping1.htm). The exact implementation depends from exact format of input data which you have (you don't included test data for `ParsedJson` which you use). – Oleg Sep 01 '14 at 15:23