Author Topic: Excluding row data in Group Totals  (Read 222 times)

pbassey

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 48
    • View Profile
Excluding row data in Group Totals
« on: February 01, 2025, 01:29:58 am »
Is there a way to exclude certain rows (based on a column value) in the Group total calculation?

For example - I have a grid result that has budget (in yellow) and transaction data (in black).  I do not want the budget amounts in the Group total calculation (see attached screen shot).

Below is my javascript code:

dataModelTransaction=  {
location: "remote",
dataType: "jsonp",
method: "GET",
url: "/CCRSearch/Reports/[email protected]",
}
colModelTransaction = [
    { dataIndx: 'grp', title: 'FASActivity', tpHide: true, editable: false, menuInHide: true, minWidth: 150 },
    { dataIndx: "FASActivity", title: "FAS Activity", editable: false, hidden: true, filter: { groupIndx: 'Source' } },   
    { title: "TRAN_TYPE", hidden: true, dataIndx: "TRAN_TYPE" },
    { title: "Source", width: 20, dataIndx: "Source" },
    { title: "Account Code", width: 20, dataIndx: "ACCNT_CODE" },
    { title: "Date", align: "right", width: 20, dataIndx: "JCDATE" },
    { title: "Description", width: 200, dataIndx: "FASDesc" },
    {
        title: "Amount", width: 85, format: '$ #,###,###.00', align: "right", dataIndx: "AMOUNT", summary: { type: "sum" },
        render: function (ui) {
            if (ui.cellData < 0) {
                return {
                    cls: 'blinkText',
                    style: { 'color': 'red'}
                };
            }
        }
    }
]
groupModel = {
    on: true,                             //grouping mode.
    pivot: false,                         //pivotMode
    checkbox: false,
    checkboxHead: true,
    select: false,
    titleIndx: 'grp',                      //v7.0.0: new option instead of titleInFirstCol
    indent: 20,
    fixCols: false,
    groupCols: ['Source'],                   //grouping along column axis.
    header: false,                         //hide grouping toolbar.
    grandSummary: true,                   //show grand summary row.     
    dataIndx: ['FASActivity'],                //grouping along row axis.
    collapsed: [true],
    useLabel: true,
    summaryEdit: false
};
           $("#Transactiondetails").html(data);
           $("#grid_transactions").pqGrid({
               height: 450,
               scrollModel: { autoFit: true },
               dataModel: dataModelTransaction,
               colModel: colModelTransaction,
               pageModel: { type: "local", rPP: 1000, strRpp: "" },
               numberCell: { show: false },
               title: "Transaction Details",
               resizable: true,
               groupModel: groupModel,
               summaryTitle: {
                   sum: ""
               }, 
               rowInit: function (ui) {
                   if (ui.rowData.TRAN_TYPE == "B") {
                       return {
                           style: { "background": "yellow" } //can also return attr (for attributes) and cls (for css classes) properties.
                       };
                   }
               }
           });


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6353
    • View Profile
Re: Excluding row data in Group Totals
« Reply #1 on: February 03, 2025, 02:20:01 pm »
Yes, rows can be excluded conditionally by defining and using custom aggregates.

Step 1: Define custom aggregate:

Code: [Select]
pq.aggregate.customSum = function( arr, col, rows ){
   //iterate over desired rows and return the aggregate.
}

Step 2: use in column definition:

Code: [Select]
title: "Amount", width: 85, format: '$ #,###,###.00', align: "right", dataIndx: "AMOUNT", summary: { type: "customSum" },

Reference: https://paramquery.com/pro/api#method-aggregate