---
title: "Tree Data - Filtering"
enterprise: true
framework: vue
version: "36.1.0"
---

# 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/vue-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 {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
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") {
  enableDevValidations();
}

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

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"
      :rowData="rowData"
      :treeData="true"
      :groupDefaultExpanded="groupDefaultExpanded"
      :getDataPath="getDataPath"></ag-grid-vue>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi | null>(null);
    const columnDefs = ref<ColDef[]>([
      { field: "created" },
      { field: "modified" },
      {
        field: "size",
        aggFunc: "sum",
        valueFormatter: (params) => {
          const sizeInKb = params.value / 1024;
          if (sizeInKb > 1024) {
            return `${+(sizeInKb / 1024).toFixed(2)} MB`;
          } else {
            return `${+sizeInKb.toFixed(2)} KB`;
          }
        },
      },
    ]);
    const defaultColDef = ref<ColDef>({
      flex: 1,
    });
    const autoGroupColumnDef = ref<AutoGroupColumnDef>({
      headerName: "File Explorer",
      minWidth: 150,
      filter: "agTextColumnFilter",
      cellRendererParams: {
        suppressCount: true,
      },
    });
    const rowData = ref<any[] | null>(getData());
    const groupDefaultExpanded = ref(-1);
    const getDataPath = ref<GetDataPath>((data) => data.path);

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

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

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      autoGroupColumnDef,
      rowData,
      groupDefaultExpanded,
      getDataPath,
      onGridReady,
    };
  },
});

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

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

## 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/vue-data-grid/tree-data-paths/#filler-groups).

#### Exclude Children when Filtering

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
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") {
  enableDevValidations();
}

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

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <div class="example-wrapper">
      <div class="example-header">
        <label>
          <span>excludeChildrenWhenTreeDataFiltering:</span>
          <input type="checkbox" id="excludeChildrenWhenTreeDataFiltering" v-on:click="toggleFilter()" checked="">
          </label>
        </div>
        <ag-grid-vue
          style="width: 100%; height: 100%;"
          @grid-ready="onGridReady"
          :columnDefs="columnDefs"
          :defaultColDef="defaultColDef"
          :autoGroupColumnDef="autoGroupColumnDef"
          :rowData="rowData"
          :treeData="true"
          :groupDefaultExpanded="groupDefaultExpanded"
          :excludeChildrenWhenTreeDataFiltering="true"
          :getDataPath="getDataPath"></ag-grid-vue>
        </div>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi | null>(null);
    const columnDefs = ref<ColDef[]>([
      { field: "created" },
      { field: "modified" },
      {
        field: "size",
        aggFunc: "sum",
        valueFormatter: (params) => {
          const sizeInKb = params.value / 1024;
          if (sizeInKb > 1024) {
            return `${+(sizeInKb / 1024).toFixed(2)} MB`;
          } else {
            return `${+sizeInKb.toFixed(2)} KB`;
          }
        },
      },
    ]);
    const defaultColDef = ref<ColDef>({
      flex: 1,
    });
    const autoGroupColumnDef = ref<AutoGroupColumnDef>({
      headerName: "File Explorer",
      minWidth: 150,
      filter: "agTextColumnFilter",
      cellRendererParams: {
        suppressCount: true,
      },
    });
    const rowData = ref<any[] | null>(getData());
    const groupDefaultExpanded = ref(-1);
    const getDataPath = ref<GetDataPath>((data) => data.path);

    function toggleFilter() {
      const checkbox = document.querySelector<HTMLInputElement>(
        "#excludeChildrenWhenTreeDataFiltering",
      )!;
      gridApi.value.setGridOption(
        "excludeChildrenWhenTreeDataFiltering",
        checkbox.checked,
      );
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

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

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      autoGroupColumnDef,
      rowData,
      groupDefaultExpanded,
      getDataPath,
      onGridReady,
      toggleFilter,
    };
  },
});

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

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

This demonstrates the following configuration:

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

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 {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
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") {
  enableDevValidations();
}

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

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <div class="example-wrapper">
      <label>
        suppressAggFilteredOnly:
        <input type="checkbox" id="suppressAggFilteredOnly" checked="" v-on:click="toggleCheckbox()">
        </label>
        <ag-grid-vue
          style="width: 100%; height: 100%;"
          @grid-ready="onGridReady"
          :columnDefs="columnDefs"
          :defaultColDef="defaultColDef"
          :autoGroupColumnDef="autoGroupColumnDef"
          :rowData="rowData"
          :treeData="true"
          :groupDefaultExpanded="groupDefaultExpanded"
          :suppressAggFilteredOnly="true"
          :getDataPath="getDataPath"></ag-grid-vue>
        </div>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi | null>(null);
    const columnDefs = ref<ColDef[]>([
      { field: "created" },
      { field: "modified" },
      {
        field: "size",
        aggFunc: "sum",
        filter: "agNumberColumnFilter",
        valueFormatter: (params) => {
          const sizeInKb = params.value / 1024;
          if (sizeInKb > 1024) {
            return `${+(sizeInKb / 1024).toFixed(2)} MB`;
          } else {
            return `${+sizeInKb.toFixed(2)} KB`;
          }
        },
      },
    ]);
    const defaultColDef = ref<ColDef>({
      flex: 1,
    });
    const autoGroupColumnDef = ref<AutoGroupColumnDef>({
      headerName: "File Explorer",
      minWidth: 150,
      cellRendererParams: {
        suppressCount: true,
      },
    });
    const rowData = ref<any[] | null>(getData());
    const groupDefaultExpanded = ref(1);
    const getDataPath = ref<GetDataPath>((data) => data.path);

    function toggleCheckbox() {
      const checkbox = document.querySelector<HTMLInputElement>(
        "#suppressAggFilteredOnly",
      )!;
      gridApi.value.setGridOption("suppressAggFilteredOnly", checkbox.checked);
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

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

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      autoGroupColumnDef,
      rowData,
      groupDefaultExpanded,
      getDataPath,
      onGridReady,
      toggleCheckbox,
    };
  },
});

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

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

This demonstrates the following configuration:

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

this.suppressAggFilteredOnly = true;
```

## Filter Components

### Tree Filter

The [Tree Filter](https://www.ag-grid.com/vue-data-grid/filter-set-tree-list/) is a version of the [Set Filter](https://www.ag-grid.com/vue-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 {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
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") {
  enableDevValidations();
}

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

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"
      :treeData="true"
      :groupDefaultExpanded="groupDefaultExpanded"
      :getDataPath="getDataPath"
      :rowData="rowData"></ag-grid-vue>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi | null>(null);
    const columnDefs = ref<ColDef[]>([
      { field: "created" },
      { field: "modified" },
      {
        field: "size",
        aggFunc: "sum",
        valueFormatter: (params) => {
          const sizeInKb = params.value / 1024;
          if (sizeInKb > 1024) {
            return `${+(sizeInKb / 1024).toFixed(2)} MB`;
          } else {
            return `${+sizeInKb.toFixed(2)} KB`;
          }
        },
      },
    ]);
    const defaultColDef = ref<ColDef>({
      flex: 1,
      minWidth: 200,
    });
    const autoGroupColumnDef = ref<AutoGroupColumnDef>({
      cellRendererParams: {
        suppressCount: true,
      },
      filter: "agSetColumnFilter",
      filterParams: {
        treeList: true,
        keyCreator: (params) => (params.value ? params.value.join("#") : null),
      },
    });
    const groupDefaultExpanded = ref(-1);
    const getDataPath = ref<GetDataPath>((data: any) => data.path);
    const rowData = ref<any[] | null>(getData());

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

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      autoGroupColumnDef,
      groupDefaultExpanded,
      getDataPath,
      rowData,
      onGridReady,
    };
  },
});

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

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

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-vue
    :autoGroupColumnDef="autoGroupColumnDef"
    /* other grid options ... */>
</ag-grid-vue>

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/vue-data-grid/filter-set-tree-list/) documentation.

### Set Filter

The [Set Filter](https://www.ag-grid.com/vue-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 {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
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") {
  enableDevValidations();
}

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

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"
      :treeData="true"
      :groupDefaultExpanded="groupDefaultExpanded"
      :groupAggFiltering="true"
      :getDataPath="getDataPath"
      :rowData="rowData"></ag-grid-vue>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi | null>(null);
    const columnDefs = ref<ColDef[]>([
      { field: "created" },
      { field: "modified" },
      {
        field: "size",
        aggFunc: "sum",
        filter: "agSetColumnFilter",
        filterParams: {
          valueFormatter: (params: ValueFormatterParams) => {
            const sizeInKb = params.value / 1024;
            if (sizeInKb > 1024) {
              return `${+(sizeInKb / 1024).toFixed(2)} MB`;
            } else {
              return `${+sizeInKb.toFixed(2)} KB`;
            }
          },
        },
        valueFormatter: (params) => {
          const sizeInKb = params.value / 1024;
          if (sizeInKb > 1024) {
            return `${+(sizeInKb / 1024).toFixed(2)} MB`;
          } else {
            return `${+sizeInKb.toFixed(2)} KB`;
          }
        },
      },
    ]);
    const defaultColDef = ref<ColDef>({
      flex: 1,
      minWidth: 200,
    });
    const autoGroupColumnDef = ref<AutoGroupColumnDef>({
      cellRendererParams: {
        suppressCount: true,
      },
    });
    const groupDefaultExpanded = ref(-1);
    const getDataPath = ref<GetDataPath>((data: any) => data.path);
    const rowData = ref<any[] | null>(getData());

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

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      autoGroupColumnDef,
      groupDefaultExpanded,
      getDataPath,
      rowData,
      onGridReady,
    };
  },
});

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

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

> **Note**
>
> When using the Set Filter with [Aggregations](https://www.ag-grid.com/vue-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/vue-data-grid/aggregation-filtering/#filtering-for-aggregated-values).
