1

Here is the Example created - Pivot Table JSFiddle example: here

Here are my grid options used:

{
    cmTemplate: { autoResizable: true },
    autoResizing: { compact: true },
    width: "600",
    height: "auto",
    rowNum: 10,
    iconSet: "fontAwesome",
    pager: true,
    caption: "Employee YTD Summary",
    groupingView: {
        groupColumnShow: [false],
        groupDataSorted: true,
        groupOrder: ["desc"]
    },
    onInitGrid: function () {
        var p = $(this).jqGrid("getGridParam"),
            userdata = p.datastr.userdata;
        p.data = $.grep(p.datastr, function (item) {
            return item.ComponentType !== "";
        });
        p.userData = userdata;
        p.datatype = "local";
    },
    footerrow: true
}

Need help in Ignoring specific row's/groups in adding from colTotals summary

This is the part of grid I have from above example

colTotalsImage

At footer of this Image colTotals section shows sum of all columns, In here I am unable to exclude the groups Benefit and AD from being summed.

expected sum at colTotals enter image description here

Working days, LOP, Benefits rows should not be summed (as they are not required) in summary column which is at bottom (red mark)

How to ignore complete group of AD and Benefit values in colTotals summary of jqGrid.

Thanks

Oleg
  • 220,925
  • 34
  • 403
  • 798
Mani Deep
  • 1,298
  • 2
  • 17
  • 33
  • I'm afraid that other readers of the text of your question will not understand the problem. You should include the most important parts of the fiddle code in the text of your question. It's good to include pictures which show which parts you need to change. Moreover I don't full understand your requirements too. Do you want to hold summary row in the AD and Benefit groups, but you want to use custom total summary calculation where the items of the groups will be skipped in the sum? Why you have so strange requirement? – Oleg Apr 22 '15 at 10:20

1 Answers1

1

It looks like you want to make custom calculation of the values in the total summary rows. In the You can for example remove colTotals: true parameter. It makes only the standard calculation of the sum of all elements. Instead of that you can add userDataOnFooter: true option, calculate the custom summary inside of onInitGrid and to place the results in userdata. The code can looks like the following

userDataOnFooter: true,
onInitGrid: function () {
    var p = $(this).jqGrid("getGridParam"), userdata = {}, colModel = p.colModel,
        iColByName = p.iColByName;
    p.datastr = $.grep(p.datastr, function (item) {
        var notToIgnore = item.ComponentType !== "", prop;
        if (notToIgnore) {
            for (prop in item) {
                if (item.hasOwnProperty(prop) &&
                        iColByName[prop] != null &&
                        colModel[iColByName[prop]].summaryType === "sum" &&
                        // !!!below is the custom criteria to skip some items!!!
                        $.inArray(item.ComponentType, ["AD", "Benefit"]) < 0) {
                    userdata[prop] = (userdata[prop] || 0) + parseFloat(item[prop]);
                }
            }
        }
        return notToIgnore;
    });
   p.datastr.userdata = userdata;
}

You can see the results on the modified data: https://jsfiddle.net/OlegKi/bkqce0s0/14/

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • is there any alternate for `onInitGrid` ? because when ever input changes, i have to use reloadGrid like ( `$("#YTDSummary").trigger("reloadGrid")` ), and this wont be called. – Mani Deep Apr 22 '15 at 11:35
  • @ManiDeep: In the case you need just move the calculation of summary in another place. You can for example include the code which calculate `userData` parameter in separate function. You can call the function *before* `.trigger("reloadGrid")`. jqGrid changes `datatype: "jsonstring"` to `datatype: "local"`. So you should set `p.userData` instead of `p.datastr.userdata` in the case. Alternatively you can calculate summary in `loadComplete` and to set the results explicitly by `footerData` method. `userDataOnFooter: true` is not required more ([here](http://stackoverflow.com/a/16162380/315935)) – Oleg Apr 22 '15 at 12:04
  • @ManiDeep: Another example of the possible callback is `beforeRequest`. (You should not forget to return `true` from the callback!). In the callback you can change `userData` parameter of jqGrid and the changes will be automatically displayed in the footer row if you use `userDataOnFooter: true` option. – Oleg Apr 22 '15 at 12:12