Search code examples
jqueryjqgridfree-jqgridjqpivot

jqGrid and jqPivot: How to sumary pivot column specify in ydimension and aggregates with count method?


I'm using jqGrid with the jqPivot.

Here my code:

$("#pvtCrewAttendance").jqGrid("jqPivot",
            data,
            {
                footerTotals: true,
                footerAggregator: "sum",
                totals: true,
                totalText: "Sumary",
                xDimension: [
                    { dataName: "CategoryName", label: "Category Name", sortorder: "desc", footerText: "Row total" },
                ],
                yDimension: [
                    { dataName: "ProductName", sorttype: "text", totalHeader: "Total in {0}" },
                ],
                aggregates: [
                    { member: "ProductName", aggregator: "count" }
                ]
            },
            // grid options
            {
                iconSet: "fontAwesome",
                cmTemplate: { autoResizable: true, width: 80 },
                shrinkToFit: false,
                autoresizeOnLoad: true,
                autoResizing: { compact: true },
                pager: false,
                rowNum: 20,
                width: 420,
                height: 100,
                rowList: [5, 10, 20, 100, "10000:All"],
                caption: "Selling statistic"
            }
        );

This my plunk demo

I want to sumary quantity of product for each category in the last column.

Any way to do it?


Solution

  • I think it's a bug in the line of code jqPivot. I'll fix it in the next days. As a workaround I suggest you to use aggregator defined as function:

    aggregates: [
        {
            member: "ProductName",
            template: "integer",
            aggregator: function (options) {
                // do the same like aggregator: "count"
                return options.previousResult + 1;
            }
        }
    ]
    

    The corresponding demo https://plnkr.co/edit/fz66phRoOLXWOuqTxF8g?p=preview displays

    enter image description here

    with "Cols total" column having correct count results.