This section covers areas of aggregation that don't fit within the other sections of the documentation.
When columns are dragged to the Values section of the Columns Tool Panel they are
assigned the sum
aggregation function by default. The default aggregation function can be overridden on a per-column
basis using the defaultAggFunc
column property.
<ag-grid-vue
:columnDefs="columnDefs"
/* other grid options ... */>
</ag-grid-vue>
this.columnDefs = [
{
field: 'gold',
// allows column to be dragged to the 'Values` section of the Columns Tool Panel
enableValue: true,
// use 'avg' as the default agg func instead of 'sum'
defaultAggFunc: 'avg',
},
];
The following example demonstrates overriding the default agg function. Note the following:
defaultAggFunc
set to avg
.mySum
.sum
as the default.Note that unlike aggFunc
you can't pass a custom aggregation function directly to defaultAggFunc
,
as demonstrated in the previous example, it must be registered first. See Registering Custom Functions for how to do this.
By default, all functions are available to all value columns. To restrict the aggregation functions available on a value
column, use the allowedAggFuncs
column property as shown below:
<ag-grid-vue
:columnDefs="columnDefs"
/* other grid options ... */>
</ag-grid-vue>
this.columnDefs = [
{
field: 'gold',
aggFunc: 'sum',
// restricts agg functions to be: `sum`, `min` and `max`
allowedAggFuncs: ['sum', 'min', 'max'],
}
];
The following example demonstrates restricting the aggregation functions. Note the following:
allowedAggFuncs
set to ['sum', 'min', 'max']
and only displays these functions in the drop-down list in the Values section column to the of the Columns Tool Panel.After the grid is initialised aggregations can be applied / retrieved / removed via the columnApi
with the following methods:
When the grid initialises, any column definitions that have aggFunc
set will be automatically added as a value column.
When aggregating, the column headers will include the aggregation function for the column. For example the header 'Bank Balance'
will become 'sum(Bank Balance)'
if you have the sum aggregation active on the column. To turn this off and display simply 'Bank Balance'
then set the grid property suppressAggFuncInHeader
.
When providing either Custom Aggregation Functions or Custom Full Row Aggregation then you will see strange calls to these functions where empty lists are provided.
The empty aggregation calls happen in the following two scenarios:
If the data changes after the aggregation is done, you can tell the grid to recompute the aggregates through the API method refreshClientSideRowModel('aggregate')
.
When aggregations are present, the grid omits aggregating all the top level rows into one parent row as this total aggregation is not shown in the grid. Some applications may wish to use this value via the API, so the property alwaysAggregateAtRootLevel
can be enabled to force this value to always calculate. The grid will still selectively calculate the top level aggregation in scenarios where it is needed, eg if groupIncludeTotalFooter
is enabled, or if the root level is being displayed for pivoting.
Continue to the next section to learn about Tree Data.