JavaScript Data GridAggregation - Total Rows

Enterprise

This section shows how to include group and grand total rows in the grid.

Enabling a Grand Total Row

A grand total row can be included in the grid by setting the grandTotalRow grid option to either "top" or "bottom". The provided value determines whether the grand total row will be included as the first or last row in the grid.

The following configuration shows how grand total rows can be included at the bottom of the grid:

const gridOptions = {
    // adds subtotals to the bottom of each row group
    grandTotalRow: 'bottom',

    // other grid options ...
}

Enabling Group Total Rows

A total row can be included in every group when using Row Grouping or Tree Data by setting the groupTotalRow grid option to either "top" or "bottom". The provided value determines whether the total row will be included as the first or last row in the group.

The following configuration shows how group total rows can be included at the bottom of every group:

const gridOptions = {
    // adds subtotals to the bottom of each row group
    groupTotalRow: 'bottom',

    // other grid options ...
}

Selectively Display Group Total Rows

Total rows can be applied to certain groups selectively by providing a callback to the groupTotalRow grid option. This callback should return "top", "bottom" or undefined and will be called for each row group to determine whether the group should display a total row.

The example above demonstrates the following configuration to display total rows for the "United States" group, and the rows grouped by the "year" field:

const gridOptions = {
    groupTotalRow: (params) => {
       const node = params.node;
       if (node && node.level === 1) return 'bottom';
       if (node && node.key === 'United States') return 'bottom';
       return undefined;
   },

    // other grid options ...
}

Keeping Group Row Values

When a total row is visible, the group row values are hidden. This behaviour can be prevented by setting the groupSuppressBlankHeader grid option to true.

The configuration below demonstrates the configuration for preventing the hiding of group row values:

const gridOptions = {
    groupSuppressBlankHeader: true,

    // other grid options ...
}

Group Column Cell Values

When using Row Grouping or Tree Data with group columns, the group cell will display "Total" by default in the footer rows.

The default agGroupCellRenderer.cellRendererParams can be provided with a totalValueGetter to configure the value displayed in this cell.

The example above demonstrates using the following configuration to display custom group column values for grand total and group total rows:

const gridOptions = {
    autoGroupColumnDef: { 
        cellRendererParams: {
            totalValueGetter: params =>  {
                const isRootLevel = params.node.level === -1;
                if (isRootLevel) {
                    return 'Grand Total';
                }
                return `Sub Total (${params.value})`;
            },
        }
    },

    // other grid options ...
}

When exporting or copying custom footers with custom group cell values, the custom content must also be added using processRowGroupCallback for export or processCellForClipboard for copying to clipboard.

Suppress Sticky Rows

All total rows stick to the top or bottom of the viewport when scrolling. This behaviour can be configured by using the suppressStickyTotalRow grid option.

The following configuration demonstrates how to suppress sticky behaviour for both grand and group total rows:

const gridOptions = {
    suppressStickyTotalRow: true,

    // other grid options ...
}

Next Up

Continue to the next section to learn about Filtering with Aggregations.