---
product: "AG Grid"
title: "Tree Data - Filtering"
description: "Filtering can be applied to Tree Data to reduce the range of displayed data."
enterprise: true
framework: angular
version: "36.2.0"
related:
    - title: "Overview"
      url: "https://www.ag-grid.com/archive/36.2.0/angular-data-grid/tree-data/"
    - title: "Supplying Data"
      url: "https://www.ag-grid.com/archive/36.2.0/angular-data-grid/tree-data-data/"
    - title: "Group Column"
      url: "https://www.ag-grid.com/archive/36.2.0/angular-data-grid/tree-data-group-column/"
    - title: "Expanding Groups"
      url: "https://www.ag-grid.com/archive/36.2.0/angular-data-grid/tree-data-opening-groups/"
    - title: "Tree Selection"
      url: "https://www.ag-grid.com/archive/36.2.0/angular-data-grid/tree-data-selection/"
    - title: "Tree Row Dragging"
      url: "https://www.ag-grid.com/archive/36.2.0/angular-data-grid/tree-data-row-dragging/"
llms: "https://www.ag-grid.com/archive/36.2.0/llms.txt"
---

# Tree Data - Filtering

Filtering can be applied to Tree Data to reduce the range of displayed data.

## Filtering

By default, when a group row passes a [Filter](https://www.ag-grid.com/archive/36.2.0/angular-data-grid/filtering-overview/), the children will also be displayed.

The example below applies a filter to the group column for 'ProjectAlpha', note that two 'ProjectAlpha' groups are displayed alongside all of their children.

#### Filtering

```ts
import { Component } from "@angular/core";
import { AgGridAngular } from "ag-grid-angular";
import {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GetDataPath,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  TextFilterModule,
  enableDevValidations,
} from "ag-grid-community";
import { TreeDataModule } from "ag-grid-enterprise";
import { getData } from "./data";

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

ModuleRegistry.registerModules([
  ClientSideRowModelModule,
  TreeDataModule,
  TextFilterModule,
]);

@Component({
  selector: "my-app",
  standalone: true,
  imports: [AgGridAngular],
  template: `<ag-grid-angular
    style="width: 100%; height: 100%;"
    [columnDefs]="columnDefs"
    [defaultColDef]="defaultColDef"
    [autoGroupColumnDef]="autoGroupColumnDef"
    [rowData]="rowData"
    [treeData]="true"
    [groupDefaultExpanded]="groupDefaultExpanded"
    [getDataPath]="getDataPath"
    (gridReady)="onGridReady($event)"
  /> `,
})
export class AppComponent {
  columnDefs: ColDef[] = [
    { field: "created" },
    { field: "modified" },
    {
      field: "size",
      aggFunc: "sum",
      valueFormatter: (params) => {
        if (params.value == null) {
          return ""; // params.value can be null/undefined here (e.g. no size for this row)
        }
        const sizeInKb = params.value / 1024;
        if (sizeInKb > 1024) {
          return `${+(sizeInKb / 1024).toFixed(2)} MB`;
        } else {
          return `${+sizeInKb.toFixed(2)} KB`;
        }
      },
    },
  ];
  defaultColDef: ColDef = {
    flex: 1,
  };
  autoGroupColumnDef: AutoGroupColumnDef = {
    headerName: "File Explorer",
    minWidth: 150,
    filter: "agTextColumnFilter",
    cellRendererParams: {
      suppressCount: true,
    },
  };
  rowData: any[] | null = getData();
  groupDefaultExpanded = -1;
  getDataPath: GetDataPath = (data) => data.path;

  onGridReady(params: GridReadyEvent) {
    params.api.setFilterModel({
      "ag-Grid-AutoColumn": {
        filterType: "text",
        type: "startsWith",
        filter: "ProjectAlpha",
      },
    });
  }
}
```

[Live example: Filtering](https://www.ag-grid.com/archive/36.2.0/examples/tree-data-filtering/filtering-simple/angular/)

## Exclude Children when Filtering

To omit children when a group row passes a filter, set `excludeChildrenWhenTreeDataFiltering` to `true` in the grid options.

The example below applies a default filter to the group column for 'ProjectAlpha', note that only one 'ProjectAlpha' group passes the filter instead of two - this is because the `Desktop -> ProjectAlpha` group is a [Filler Group](https://www.ag-grid.com/archive/36.2.0/angular-data-grid/tree-data-paths/#filler-groups).

#### Exclude Children when Filtering

```ts
import { Component } from "@angular/core";
import { AgGridAngular } from "ag-grid-angular";
import "./styles.css";
import {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GetDataPath,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  TextFilterModule,
  enableDevValidations,
} from "ag-grid-community";
import { TreeDataModule } from "ag-grid-enterprise";
import { getData } from "./data";

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

ModuleRegistry.registerModules([
  ClientSideRowModelModule,
  TreeDataModule,
  TextFilterModule,
]);

@Component({
  selector: "my-app",
  standalone: true,
  imports: [AgGridAngular],
  template: `<div class="example-wrapper">
    <div class="example-header">
      <label>
        <span>excludeChildrenWhenTreeDataFiltering:</span>
        <input
          type="checkbox"
          id="excludeChildrenWhenTreeDataFiltering"
          (click)="toggleFilter()"
          checked=""
        />
      </label>
    </div>
    <ag-grid-angular
      style="width: 100%; height: 100%;"
      [columnDefs]="columnDefs"
      [defaultColDef]="defaultColDef"
      [autoGroupColumnDef]="autoGroupColumnDef"
      [rowData]="rowData"
      [treeData]="true"
      [groupDefaultExpanded]="groupDefaultExpanded"
      [excludeChildrenWhenTreeDataFiltering]="true"
      [getDataPath]="getDataPath"
      (gridReady)="onGridReady($event)"
    />
  </div> `,
})
export class AppComponent {
  private gridApi!: GridApi;

  columnDefs: ColDef[] = [
    { field: "created" },
    { field: "modified" },
    {
      field: "size",
      aggFunc: "sum",
      valueFormatter: (params) => {
        if (params.value == null) {
          return ""; // params.value can be null/undefined here (e.g. no size for this row)
        }
        const sizeInKb = params.value / 1024;
        if (sizeInKb > 1024) {
          return `${+(sizeInKb / 1024).toFixed(2)} MB`;
        } else {
          return `${+sizeInKb.toFixed(2)} KB`;
        }
      },
    },
  ];
  defaultColDef: ColDef = {
    flex: 1,
  };
  autoGroupColumnDef: AutoGroupColumnDef = {
    headerName: "File Explorer",
    minWidth: 150,
    filter: "agTextColumnFilter",
    cellRendererParams: {
      suppressCount: true,
    },
  };
  rowData: any[] | null = getData();
  groupDefaultExpanded = -1;
  getDataPath: GetDataPath = (data) => data.path;

  toggleFilter() {
    const checkbox = document.querySelector<HTMLInputElement>(
      "#excludeChildrenWhenTreeDataFiltering",
    )!;
    this.gridApi.setGridOption(
      "excludeChildrenWhenTreeDataFiltering",
      checkbox.checked,
    );
  }

  onGridReady(params: GridReadyEvent) {
    this.gridApi = params.api;

    params.api.setFilterModel({
      "ag-Grid-AutoColumn": {
        filterType: "text",
        type: "startsWith",
        filter: "ProjectAlpha",
      },
    });
  }
}
```

[Live example: Exclude Children when Filtering](https://www.ag-grid.com/archive/36.2.0/examples/tree-data-filtering/filtering-exclude-children/angular/)

This demonstrates the following configuration:

```ts
<ag-grid-angular
    [excludeChildrenWhenTreeDataFiltering]="excludeChildrenWhenTreeDataFiltering"
    /* other grid options ... */ />

this.excludeChildrenWhenTreeDataFiltering = true;
```

## Ignore Filters when Aggregating Values

When using Tree Data and filters, the aggregates are only calculated from the rows which pass the filter. This can be changed by enabling the grid option `suppressAggFilteredOnly`.

The example below has a filter applied resulting in only one of the `Documents` children being displayed. Note that when the `suppressAggFilteredOnly` option is toggled on, the `Documents` group aggregation will display the sum of all children, regardless of the filter.

#### Aggregated Values Based on Pre-Filtered Data

```ts
import { Component } from "@angular/core";
import { AgGridAngular } from "ag-grid-angular";
import "./style.css";
import {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GetDataPath,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  NumberFilterModule,
  TextFilterModule,
  enableDevValidations,
} from "ag-grid-community";
import { TreeDataModule } from "ag-grid-enterprise";
import { getData } from "./data";

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

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

@Component({
  selector: "my-app",
  standalone: true,
  imports: [AgGridAngular],
  template: `<div class="example-wrapper">
    <label>
      suppressAggFilteredOnly:
      <input
        type="checkbox"
        id="suppressAggFilteredOnly"
        checked=""
        (click)="toggleCheckbox()"
      />
    </label>
    <ag-grid-angular
      style="width: 100%; height: 100%;"
      [columnDefs]="columnDefs"
      [defaultColDef]="defaultColDef"
      [autoGroupColumnDef]="autoGroupColumnDef"
      [rowData]="rowData"
      [treeData]="true"
      [groupDefaultExpanded]="groupDefaultExpanded"
      [suppressAggFilteredOnly]="true"
      [getDataPath]="getDataPath"
      (gridReady)="onGridReady($event)"
    />
  </div> `,
})
export class AppComponent {
  private gridApi!: GridApi;

  columnDefs: ColDef[] = [
    { field: "created" },
    { field: "modified" },
    {
      field: "size",
      aggFunc: "sum",
      filter: "agNumberColumnFilter",
      valueFormatter: (params) => {
        if (params.value == null) {
          return ""; // params.value can be null/undefined here (e.g. no size for this row)
        }
        const sizeInKb = params.value / 1024;
        if (sizeInKb > 1024) {
          return `${+(sizeInKb / 1024).toFixed(2)} MB`;
        } else {
          return `${+sizeInKb.toFixed(2)} KB`;
        }
      },
    },
  ];
  defaultColDef: ColDef = {
    flex: 1,
  };
  autoGroupColumnDef: AutoGroupColumnDef = {
    headerName: "File Explorer",
    minWidth: 150,
    cellRendererParams: {
      suppressCount: true,
    },
  };
  rowData: any[] | null = getData();
  groupDefaultExpanded = 1;
  getDataPath: GetDataPath = (data) => data.path;

  toggleCheckbox() {
    const checkbox = document.querySelector<HTMLInputElement>(
      "#suppressAggFilteredOnly",
    )!;
    this.gridApi.setGridOption("suppressAggFilteredOnly", checkbox.checked);
  }

  onGridReady(params: GridReadyEvent) {
    this.gridApi = params.api;

    params.api.setFilterModel({
      size: {
        filterType: "number",
        type: "equals",
        filter: 5193728,
      },
    });
  }
}
```

[Live example: Aggregated Values Based on Pre-Filtered Data](https://www.ag-grid.com/archive/36.2.0/examples/tree-data-filtering/group-agg-filtering/angular/)

This demonstrates the following configuration:

```ts
<ag-grid-angular
    [suppressAggFilteredOnly]="suppressAggFilteredOnly"
    /* other grid options ... */ />

this.suppressAggFilteredOnly = true;
```

## Filter Components

### Tree Filter

The [Tree Filter](https://www.ag-grid.com/archive/36.2.0/angular-data-grid/filter-set-tree-list/) is a version of the [Set Filter](https://www.ag-grid.com/archive/36.2.0/angular-data-grid/filter-set/) that is designed to work with hierarchical data by displaying the set filter in a tree structure that matches the data.

The example below demonstrates the Tree Filter on the Group column:

#### Tree List

```ts
import { Component } from "@angular/core";
import { AgGridAngular } from "ag-grid-angular";
import {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GetDataPath,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  FiltersToolPanelModule,
  SetFilterModule,
  TreeDataModule,
} from "ag-grid-enterprise";
import { getData } from "./data";

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

ModuleRegistry.registerModules([
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  FiltersToolPanelModule,
  ColumnMenuModule,
  ContextMenuModule,
  SetFilterModule,
  TreeDataModule,
]);

@Component({
  selector: "my-app",
  standalone: true,
  imports: [AgGridAngular],
  template: `<ag-grid-angular
    style="width: 100%; height: 100%;"
    [columnDefs]="columnDefs"
    [defaultColDef]="defaultColDef"
    [autoGroupColumnDef]="autoGroupColumnDef"
    [treeData]="true"
    [groupDefaultExpanded]="groupDefaultExpanded"
    [getDataPath]="getDataPath"
    [rowData]="rowData"
  /> `,
})
export class AppComponent {
  columnDefs: ColDef[] = [
    { field: "created" },
    { field: "modified" },
    {
      field: "size",
      aggFunc: "sum",
      valueFormatter: (params) => {
        if (params.value == null) {
          return ""; // params.value can be null/undefined here (e.g. no size for this row)
        }
        const sizeInKb = params.value / 1024;
        if (sizeInKb > 1024) {
          return `${+(sizeInKb / 1024).toFixed(2)} MB`;
        } else {
          return `${+sizeInKb.toFixed(2)} KB`;
        }
      },
    },
  ];
  defaultColDef: ColDef = {
    flex: 1,
    minWidth: 200,
  };
  autoGroupColumnDef: AutoGroupColumnDef = {
    cellRendererParams: {
      suppressCount: true,
    },
    filter: "agSetColumnFilter",
    filterParams: {
      treeList: true,
      keyCreator: (params) => (params.value ? params.value.join("#") : null),
    },
  };
  groupDefaultExpanded = -1;
  getDataPath: GetDataPath = (data: any) => data.path;
  rowData: any[] | null = getData();
}
```

[Live example: Tree List](https://www.ag-grid.com/archive/36.2.0/examples/tree-data-filtering/tree-list-filtering/angular/)

This demonstrates the following configuration to enable the Tree List Filter. Note that a `keyCreator` must be used to convert each path into a unique string:

```ts
<ag-grid-angular
    [autoGroupColumnDef]="autoGroupColumnDef"
    /* other grid options ... */ />

this.autoGroupColumnDef = {
    filter: 'agSetColumnFilter',
    filterParams: {
        treeList: true,
        keyCreator: (params) => (params.value ? params.value.join('#') : null),
    },
};
```

For further information, refer to the [Tree Filter](https://www.ag-grid.com/archive/36.2.0/angular-data-grid/filter-set-tree-list/) documentation.

### Set Filter

The [Set Filter](https://www.ag-grid.com/archive/36.2.0/angular-data-grid/filter-set/) can be used with Tree Data to list all unique values across each level of the group hierarchy.

The example below demonstrates the Set Filter on the Size column.

#### Set List

```ts
import { Component } from "@angular/core";
import { AgGridAngular } from "ag-grid-angular";
import {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GetDataPath,
  GridApi,
  GridOptions,
  GridReadyEvent,
  IsRowFilterable,
  ModuleRegistry,
  ValueFormatterParams,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  FiltersToolPanelModule,
  SetFilterModule,
  TreeDataModule,
} from "ag-grid-enterprise";
import { getData } from "./data";

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

ModuleRegistry.registerModules([
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  FiltersToolPanelModule,
  ColumnMenuModule,
  ContextMenuModule,
  SetFilterModule,
  TreeDataModule,
]);

@Component({
  selector: "my-app",
  standalone: true,
  imports: [AgGridAngular],
  template: `<ag-grid-angular
    style="width: 100%; height: 100%;"
    [columnDefs]="columnDefs"
    [defaultColDef]="defaultColDef"
    [autoGroupColumnDef]="autoGroupColumnDef"
    [treeData]="true"
    [groupDefaultExpanded]="groupDefaultExpanded"
    [groupAggFiltering]="true"
    [getDataPath]="getDataPath"
    [rowData]="rowData"
  /> `,
})
export class AppComponent {
  columnDefs: ColDef[] = [
    { field: "created" },
    { field: "modified" },
    {
      field: "size",
      aggFunc: "sum",
      filter: "agSetColumnFilter",
      filterParams: {
        valueFormatter: (params: ValueFormatterParams) => {
          if (params.value == null) {
            return ""; // params.value can be null/undefined here (e.g. no size for this row)
          }
          const sizeInKb = params.value / 1024;
          if (sizeInKb > 1024) {
            return `${+(sizeInKb / 1024).toFixed(2)} MB`;
          } else {
            return `${+sizeInKb.toFixed(2)} KB`;
          }
        },
      },
      valueFormatter: (params) => {
        if (params.value == null) {
          return ""; // params.value can be null/undefined here (e.g. no size for this row)
        }
        const sizeInKb = params.value / 1024;
        if (sizeInKb > 1024) {
          return `${+(sizeInKb / 1024).toFixed(2)} MB`;
        } else {
          return `${+sizeInKb.toFixed(2)} KB`;
        }
      },
    },
  ];
  defaultColDef: ColDef = {
    flex: 1,
    minWidth: 200,
  };
  autoGroupColumnDef: AutoGroupColumnDef = {
    cellRendererParams: {
      suppressCount: true,
    },
  };
  groupDefaultExpanded = -1;
  getDataPath: GetDataPath = (data: any) => data.path;
  rowData: any[] | null = getData();
}
```

[Live example: Set List](https://www.ag-grid.com/archive/36.2.0/examples/tree-data-filtering/set-list-filtering/angular/)

> **Note**
>
> When using the Set Filter with [Aggregations](https://www.ag-grid.com/archive/36.2.0/angular-data-grid/aggregation/) the set filter options can change when applying filters.
>
> To prevent this it is advised that you [Enable Aggregate Value Filtering](https://www.ag-grid.com/archive/36.2.0/angular-data-grid/aggregation-filtering/#filtering-for-aggregated-values).
