Angular Data GridAggregation - Other

angular logo
Enterprise

This section covers areas of aggregation that don't fit within the other sections of the documentation.

Default Aggregation Function

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-angular
    [columnDefs]="columnDefs"
    /* other grid options ... */>
</ag-grid-angular>

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:

  • The Gold column is configured with defaultAggFunc set to avg.
  • Drag the Gold column to the Values section of the Columns Tool Panel and note that it is assigned the 'avg' function.
  • The Silver column is configured to use a custom aggregation function as its default. Drag the Silver column to the Values section and note that it is assigned the function mySum.
  • Dragging the Bronze column will use 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.

Restricting Aggregation Functions

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-angular
    [columnDefs]="columnDefs"
    /* other grid options ... */>
</ag-grid-angular>

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:

  • The Gold column is configured with 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.
  • The Silver column shows all available agg functions as it hasn't been restricted.

Aggregation API

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