---
product: "AG Grid"
title: "Aggregation"
description: "Apply custom or provided functions to values to calculate group values in the grid."
enterprise: true
framework: vue
version: "36.2.0"
related:
    - title: "Configure Columns"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/aggregation-columns/"
    - title: "Custom Functions"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/aggregation-custom-functions/"
    - title: "Total Rows"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/aggregation-total-rows/"
    - title: "Filtering "
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/aggregation-filtering/"
    - title: "Show Values As"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/aggregation-show-values-as/"
llms: "https://www.ag-grid.com/archive/36.2.0/llms.txt"
---

# Aggregation

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

#### Aggregation Overview

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
import {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  GridReadyEvent,
  IAggFuncs,
  ModuleRegistry,
  UseGroupTotalRow,
  enableDevValidations,
} from "ag-grid-community";
import { ColumnMenuModule, RowGroupingModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

if (process.env.NODE_ENV !== "production") {
  // Enable extended validations only for development
  enableDevValidations();
}

ModuleRegistry.registerModules([
  ClientSideRowModelModule,
  ColumnMenuModule,
  RowGroupingModule,
]);

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <ag-grid-vue
      style="width: 100%; height: 100%;"
      @grid-ready="onGridReady"
      :columnDefs="columnDefs"
      :defaultColDef="defaultColDef"
      :autoGroupColumnDef="autoGroupColumnDef"
      :grandTotalRow="grandTotalRow"
      :groupTotalRow="groupTotalRow"
      :aggFuncs="aggFuncs"
      :rowData="rowData"></ag-grid-vue>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi<IOlympicData> | null>(null);
    const columnDefs = ref<ColDef[]>([
      { field: "country", rowGroup: true, hide: true },
      { field: "bronze", aggFunc: "sum" },
      { field: "silver", aggFunc: "avg" },
      { field: "gold", aggFunc: "custom_Mode" },
    ]);
    const defaultColDef = ref<ColDef>({
      flex: 1,
      minWidth: 100,
    });
    const autoGroupColumnDef = ref<AutoGroupColumnDef>({
      minWidth: 200,
    });
    const grandTotalRow = ref<"top" | "bottom" | "pinnedTop" | "pinnedBottom">(
      "bottom",
    );
    const groupTotalRow = ref<"top" | "bottom" | UseGroupTotalRow>("bottom");
    const aggFuncs = ref<IAggFuncs>({
      custom_Mode: (params) => {
        const counts = new Map<number, number>();
        let mode = null;
        let maxCount = 0;
        for (const value of params.values) {
          if (value == null) continue;
          const count = (counts.get(value) ?? 0) + 1;
          counts.set(value, count);
          if (count > maxCount) {
            maxCount = count;
            mode = value;
          }
        }
        return mode;
      },
    });
    const rowData = ref<IOlympicData[]>(null);

    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

      const updateData = (data) => (rowData.value = data);

      fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
        .then((resp) => resp.json())
        .then((data) => updateData(data));
    };

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      autoGroupColumnDef,
      grandTotalRow,
      groupTotalRow,
      aggFuncs,
      rowData,
      onGridReady,
    };
  },
});

const app = createApp(VueExample);
app.mount("#app");
```

[Live example: Aggregation Overview](https://www.ag-grid.com/archive/36.2.0/examples/aggregation/aggregation-overview/vue3/)

This example also demonstrates using the built in aggregations of `sum` and `avg` as well as a custom `mode` implementation via a [Custom Aggregation Function](https://www.ag-grid.com/archive/36.2.0/vue-data-grid/aggregation-custom-functions/). [Group and Grand Total Rows](https://www.ag-grid.com/archive/36.2.0/vue-data-grid/aggregation-total-rows/) are also enabled.

## 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:

```ts
<ag-grid-vue
    :columnDefs="columnDefs"
    /* other grid options ... */>
</ag-grid-vue>

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

## API Reference

> **Note**
>
> The aggregation state can be saved and restored as part of [Grid State](https://www.ag-grid.com/archive/36.2.0/vue-data-grid/grid-state/).

Aggregations can be configured using the following column properties:

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `aggFunc` | `string \| IAggFunc \| null` |  |  |  |
| `initialAggFunc` | `string \| IAggFunc` |  |  |  |
| `valueIndex` | `number` |  |  |  |
| `initialValueIndex` | `number` |  |  |  |
| `enableValue` | `boolean` |  |  |  |
| `allowedAggFuncs` | `string[]` |  |  |  |
| `defaultAggFunc` | `string` |  |  |  |
| `showValuesAs` | `ShowValuesAsType \| ShowValuesAs \| null` |  |  |  |
| `initialShowValuesAs` | `ShowValuesAsType \| ShowValuesAs` |  |  |  |
| `showValuesAsDef` | `ShowValuesAsDef \| null` |  |  |  |
| `enableShowValuesAs` | `boolean` |  |  |  |

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

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `aggFuncs` | `IAggFuncs` |  |  |  |
| `groupTotalRow` | `'top' \| 'bottom' \| UseGroupTotalRow` |  |  |  |
| `grandTotalRow` | `'top' \| 'bottom' \| 'pinnedTop' \| 'pinnedBottom'` |  |  |  |
| `suppressAggFuncInHeader` | `boolean` |  |  |  |
| `aggregateOnlyChangedColumns` | `boolean` |  |  |  |
| `suppressAggFilteredOnly` | `boolean` |  |  |  |
| `groupAggFiltering` | `boolean \| IsRowFilterable` |  |  |  |
| `groupSuppressBlankHeader` | `boolean` |  |  |  |
| `suppressStickyTotalRow` | `boolean \| 'grand' \| 'group'` |  |  |  |
| `alwaysAggregateAtRootLevel` | `boolean` |  |  |  |
| `getGroupRowAgg` | `GetGroupRowAgg` |  |  |  |

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

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `getValueColumns` | `Function` |  |  |  |
| `addValueColumns` | `Function` |  |  |  |
| `removeValueColumns` | `Function` |  |  |  |
| `setValueColumns` | `Function` |  |  |  |
| `setColumnAggFunc` | `Function` |  |  |  |
| `addAggFuncs` | `Function` |  |  |  |
| `clearAggFuncs` | `Function` |  |  |  |

## Editing Aggregated Values

Group row cells displaying aggregated values can be made editable, allowing users to edit a group total and have the change distributed back down to descendant rows. The built-in distribution supports all standard aggregation functions and can be customised per column.

See [Editing Group Rows](https://www.ag-grid.com/archive/36.2.0/vue-data-grid/grouping-edit/) for full details on `groupRowEditable`, `groupRowValueSetter`, and distribution strategies.

## Retrieving Aggregated Children

The method `rowNode.getAggregatedChildren(colKey)` with Client Side Row Model returns the immediate children that contribute to the aggregation of a group row. This is useful when implementing custom logic based on aggregated data or when [Editing Group Rows](https://www.ag-grid.com/archive/36.2.0/vue-data-grid/grouping-edit/) to update child rows accordingly.

- For regular group columns, returns the direct children used for aggregation (respecting `suppressAggFilteredOnly` and `groupAggFiltering` settings).
- For pivot columns on leaf groups, returns only the children matching the column's pivot keys.
- Returns an empty array for leaf (non-group) rows.

### Retrieving All Leaf Descendants

Pass `true` as the second argument to collect all descendant leaf (data) rows recursively:

```ts
const allLeaves = groupNode.getAggregatedChildren(colKey, true);
```

This traverses the full group hierarchy and returns every non-group row that ultimately contributes to the group's aggregated value, respecting the same filtering and pivot rules as the non-recursive call.

> **Note**
>
> Calling `getAggregatedChildren(colKey, true)` allocates a new array and visits every descendant node. On large or deeply nested datasets this can be expensive, so prefer the non-recursive form when only immediate children are needed.
