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:
const gridOptions = {
columnDefs: [
{ field: 'gold', aggFunc: 'sum' },
{ field: 'silver', aggFunc: 'max' },
{ field: 'bronze', aggFunc: 'avg' },
// ... other column definitions
],
// other grid options ...
}
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. |
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. |
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. |
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:
A map of 'function name' to 'function' for custom aggregation functions. |
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. |
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. |
When true , column headers won't include the aggFunc name, e.g. 'sum(Bank Balance) ' will just be 'Bank Balance' . |
When using change detection, only the updated column will be re-aggregated. |
Set to true so that aggregations are not impacted by filtering. |
Set to determine whether filters should be applied on aggregated group values. |
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. |
Suppress the sticky behaviour of the total rows, can be suppressed individually by passing 'grand' or 'group' . |
When using aggregations, the grid will always calculate the root level aggregation value. |
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:
Get a list of the existing value columns. |
Add the given list of columns to the existing set of value columns. |
Remove the given list of columns from the existing set of value columns. |
Set the value columns to the provided list of columns. |
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. |
Add aggregations function with the specified keys. |
Clears all aggregation functions (including those provided by the grid). |
Next Up
Continue to the next section to learn how to Configure Columns.