---
title: "Aggregation - Filtering"
enterprise: true
framework: javascript
version: "36.1.0"
---

# Aggregation - Filtering

Filtering can be configured to impact aggregate values in the grid.

## Ignore Filters when Aggregating

When using [Filters](https://www.ag-grid.com/javascript-data-grid/filtering-overview/) and [Aggregations](https://www.ag-grid.com/javascript-data-grid/aggregation/) together, the aggregated values reflect only the rows which have passed the filter. This can be changed to instead ignore applied filters by using the `suppressAggFilteredOnly` grid option.

#### Aggregation and Filters

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule } from "ag-grid-enterprise";

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

ModuleRegistry.registerModules([
  NumberFilterModule,
  ClientSideRowModelModule,
  RowGroupingModule,
  TextFilterModule,
]);

let gridApi: GridApi;

const gridOptions: GridOptions = {
  columnDefs: [
    { field: "country", rowGroup: true, hide: true },
    { field: "year", rowGroup: true, hide: true },
    { field: "sport", filter: "agTextColumnFilter", floatingFilter: true },
    { field: "gold", aggFunc: "sum" },
    { field: "silver", aggFunc: "sum" },
    { field: "bronze", aggFunc: "sum" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 150,
  },
  autoGroupColumnDef: {
    minWidth: 300,
  },
  groupTotalRow: "bottom",
  onGridReady: (params) => {
    params.api.setFilterModel({
      sport: {
        type: "contains",
        filter: "Swimming",
      },
    });
  },
};

function toggleProperty() {
  const enable = document.querySelector<HTMLInputElement>(
    "#suppressAggFilteredOnly",
  )!.checked;
  gridApi.setGridOption("suppressAggFilteredOnly", enable);
}

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));

if (typeof window !== "undefined") {
  // Attach external event handlers to window so they can be called from index.html
  (<any>window).toggleProperty = toggleProperty;
}
```

[Live example: Aggregation and Filters](https://www.ag-grid.com/examples/aggregation-filtering/filters/typescript)

The example above demonstrates the impact of the `suppressAggFilteredOnly` grid option. This can be enabled as shown:

```js
const gridOptions = {
    suppressAggFilteredOnly: true,

    // other grid options ...
}
```

## Filtering for Aggregated Values

The grid only applies filters to leaf level rows, this can be toggled to instead also apply filtering to group rows by enabling the `groupAggFiltering` grid option, allowing filters to also apply against the aggregated values.

#### Group and Leaf Aggregate Filtering

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ContextMenuModule,
  RowGroupingModule,
  SetFilterModule,
} from "ag-grid-enterprise";

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

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

let gridApi: GridApi;

const gridOptions: GridOptions = {
  columnDefs: [
    { field: "country", rowGroup: true, hide: true },
    { field: "year" },
    { field: "total", aggFunc: "sum", filter: "agNumberColumnFilter" },
  ],
  defaultColDef: {
    flex: 1,
    floatingFilter: true,
  },
  autoGroupColumnDef: {
    field: "athlete",
  },
  groupDefaultExpanded: -1,
  groupAggFiltering: true,

  onGridReady: (params) => {
    document.querySelector<HTMLInputElement>("#groupAggFiltering")!.checked =
      true;
    params.api.setFilterModel({
      total: {
        type: "contains",
        filter: "192",
      },
    });
  },
};

function toggleProperty() {
  const enable =
    document.querySelector<HTMLInputElement>("#groupAggFiltering")!.checked;
  gridApi.setGridOption("groupAggFiltering", enable);
}

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));

if (typeof window !== "undefined") {
  // Attach external event handlers to window so they can be called from index.html
  (<any>window).toggleProperty = toggleProperty;
}
```

[Live example: Group and Leaf Aggregate Filtering](https://www.ag-grid.com/examples/aggregation-filtering/agg-filtering-all/typescript)

> **Note**
>
> Take note of the following while using `groupAggFiltering`:
>
> - When a group row passes a filter, it also includes all of its descendent rows in the filtered results.
> - The `suppressAggFilteredOnly` grid option will be implicitly enabled.
> - [Set Filters](https://www.ag-grid.com/javascript-data-grid/filter-set/) will only work with leaf rows.

The following configuration demonstrates how to enable group aggregation filtering:

```js
const gridOptions = {
    groupAggFiltering: true,

    // other grid options ...
}
```

### Configure by Callback

When filtering for aggregated values the filter applies to all group rows by default. This can be configured more granularly by instead providing the `groupAggFiltering` grid option with a callback function.

The example below demonstrates a grid configured to apply filters only to aggregated values, and not the leaf rows:

#### Group-Only Aggregate Filtering

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ContextMenuModule,
  RowGroupingModule,
} from "ag-grid-enterprise";

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

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

let gridApi: GridApi;

const gridOptions: GridOptions = {
  columnDefs: [
    { field: "country", rowGroup: true, hide: true },
    { field: "year" },
    { field: "total", aggFunc: "sum", filter: "agNumberColumnFilter" },
  ],
  defaultColDef: {
    flex: 1,
    floatingFilter: true,
  },
  autoGroupColumnDef: {
    field: "athlete",
  },
  groupDefaultExpanded: -1,
  groupAggFiltering: (params) => !!params.node.group,
};

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Group-Only Aggregate Filtering](https://www.ag-grid.com/examples/aggregation-filtering/agg-filtering-group/typescript)

The configuration below demonstrates how to only apply test filters against group rows, and not leaf rows:

```js
const gridOptions = {
    groupAggFiltering: (params) => !!params.node.group,

    // other grid options ...
}
```
