Angular Data GridAggregation

Enterprise

Apply custom or provided functions to values to calculate group values in the grid.

Enabling Aggregation

Aggregations can be enabled in the grid by setting the aggFunc column definition value to one of: sum, min, max, count, avg, first, or last.

The following configuration demonstrates how to enable aggregation on a column:

<ag-grid-angular
    [columnDefs]="columnDefs"
    /* other grid options ... */ />

this.columnDefs = [
    { field: 'gold', aggFunc: 'sum' },
    { field: 'silver', aggFunc: 'max' },
    { field: 'bronze', aggFunc: 'avg' },
    // ... other column definitions
];

API Reference

Aggregations can be configured using the following column properties:

Name of function to use for aggregation. In-built options are: sum, min, max, count, avg, first, last. Also accepts a custom aggregation name or an aggregation function.
Same as aggFunc, except only applied when creating a new column. Not applied when updating column definitions.
enableValue
boolean
default: false
Set to true if you want to be able to aggregate by this column via the GUI. This will not block the API or properties being used to achieve aggregation.
allowedAggFuncs
string[]
Aggregation functions allowed on this column e.g. ['sum', 'avg']. If missing, all installed functions are allowed. This will only restrict what the GUI allows a user to select, it does not impact when you set a function via the API.
defaultAggFunc
string
default: 'sum'
The name of the aggregation function to use for this column when it is enabled via the GUI. Note that this does not immediately apply the aggregation function like aggFunc

Aggregation functions can be registered with the grid using the following grid options:

aggFuncs
{ [key: string]: IAggFunc }
A map of 'function name' to 'function' for custom aggregation functions.
groupTotalRow
'top' | 'bottom' | UseGroupTotalRow
When provided, an extra row group total row will be inserted into row groups at the specified position, to display when the group is expanded. This row will contain the aggregate values for the group. If a callback function is provided, it can be used to selectively determine which groups will have a total row added.
grandTotalRow
'top' | 'bottom'
When provided, an extra grand total row will be inserted into the grid at the specified position. This row displays the aggregate totals of all rows in the grid.
suppressAggFuncInHeader
boolean
default: false
When true, column headers won't include the aggFunc name, e.g. 'sum(Bank Balance)' will just be 'Bank Balance'.
aggregateOnlyChangedColumns
boolean
default: false
When using change detection, only the updated column will be re-aggregated.
suppressAggFilteredOnly
boolean
default: false
Set to true so that aggregations are not impacted by filtering.
groupAggFiltering
boolean | IsRowFilterable
default: false
Set to determine whether filters should be applied on aggregated group values.
groupSuppressBlankHeader
boolean
default: false
If true, and showing footer, aggregate data will always be displayed at both the header and footer levels. This stops the possibly undesirable behaviour of the header details 'jumping' to the footer on expand.
suppressStickyTotalRow
boolean | 'grand' | 'group'
Suppress the sticky behaviour of the total rows, can be suppressed individually by passing 'grand' or 'group'.
alwaysAggregateAtRootLevel
boolean
default: false
When using aggregations, the grid will always calculate the root level aggregation value.
getGroupRowAgg
Function
Callback to use when you need access to more then the current column for aggregation.

After the grid is initialised aggregations can be applied / retrieved / removed via the api with the following methods:

getValueColumns
Function
Get a list of the existing value columns.
addValueColumns
Function
Add the given list of columns to the existing set of value columns.
removeValueColumns
Function
Remove the given list of columns from the existing set of value columns.
setValueColumns
Function
Set the value columns to the provided list of columns.
setColumnAggFunc
Function
Sets the agg function for a column. aggFunc can be one of the built-in aggregations or a custom aggregation by name or direct function.
addAggFuncs
Function
Add aggregations function with the specified keys.
clearAggFuncs
Function
Clears all aggregation functions (including those provided by the grid).

Next Up

Continue to the next section to learn how to Configure Columns.