# Filtering

The MultiSelectTree component provides filtering capabilities that work with both hierarchical and flat data structures. When filtering is enabled, users can type in a filter input within the popup list, which allows them to quickly find specific nodes from tree datasets. The component also allows controlling how the nodes expand during filtering operations.

The easiest approach to enable filtering in the MultiSelectTree is to use [built-in directives](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/multiselecttree/data-binding#built-in-directives), which require minimal setup and handle the filtering logic automatically. For more advanced scenarios, you can implement custom filtering with manual event handling.

> The MultiSelectTree does not support server-side data filtering.

The following example demonstrates how to implement automatic filtering in the MultiSelectTree when using a hierarchical dataset.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/multiselecttree/filtering/hierarchy/source.txt)

## Automatic Filtering

For the automatic filtering implementation, use the [built-in data-binding directives](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/multiselecttree/data-binding#built-in-directives) when your entire dataset is available on the client. This approach provides the simplest setup and requires no custom event handling or filtering logic.

To enable automatic filtering, set the [`filterable`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreecomponent#filterable) property to `true` and choose the appropriate data-binding approach based on your data structure:

* [Hierarchy binding](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/multiselecttree/filtering#hierarchy-binding)—Use [`kendoMultiSelectTreeHierarchyBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreehierarchybindingdirective) for hierarchical data with parent-child relationships.
* [Flat binding](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/multiselecttree/filtering#flat-binding)—Use [`kendoMultiSelectTreeFlatBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreeflatbindingdirective) for flat data that needs to be transformed into a tree structure.

You can also customize the filtering behavior by configuring suitable [filter settings](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/multiselecttree/filtering#filter-settings) to control case sensitivity and search operators.

### Hierarchy Binding

Use the [`kendoMultiSelectTreeHierarchyBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreehierarchybindingdirective) directive when your data is structured hierarchically with parent-child relationships. This binding approach preserves the natural tree structure and allows filtering to work across all levels of the hierarchy.

```HTML

<kendo-multiselecttree
    [kendoMultiSelectTreeHierarchyBinding]="data"
    [filterable]="true"
    childrenField="items"
    textField="text"
    valueField="text"
>
</kendo-multiselecttree>
```

```TypeScript
public data: any[] = [
    {
        text: "Furniture",
        items: [
            { text: "Tables & Chairs" },
            {
                text: "Sofas",
                items: [
                    { text: "Bean Bag" },
                    { text: "Armchair" },
                    { text: "Modular" },
                ],
            },
            { text: "Occasional" },
        ],
    }
];
```

### Flat Binding

Use the [`kendoMultiSelectTreeFlatBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreeflatbindingdirective) directive when your data is in a flat structure that needs to be transformed into a tree. This approach is ideal when working with normalized data or when parent-child relationships are defined through object fields.

The following example demonstrates how to use the flat binding directive with filtering enabled.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/multiselecttree/filtering/flat/source.txt)

### Filter Settings

You can fine-tune the filtering behavior by defining a [`filterSettings`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreehierarchybindingdirective#filtersettings) configuration object when using either of the data-binding directives. The settings allow you to control the search operator and case sensitivity, providing flexibility in how users can search through the tree data.

```HTML
<kendo-multiselecttree
    [kendoMultiSelectTreeHierarchyBinding]="data"
    [filterable]="true"
    [filterSettings]="filterSettings"
    ...
>
</kendo-multiselecttree>
```

```TypeScript
// Preserve case and match only items that start with the filter text.
public filterSettings: TreeViewFilterSettings = {
    ignoreCase: false,
    operator: "startswith",
};
```

The following example demonstrates how to configure both the `ignoreCase` and `operator` filter settings.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/multiselecttree/filtering/filter-settings/source.txt)

## Auto-Expanding Items while Filtering

When filtering tree data, you can control how the MultiSelectTree automatically expands nodes to reveal matching items. This feature enhances user experience by expanding relevant tree nodes, making it easier to navigate the filtered results.

To enable the auto-expanding functionality, perform the following configuration steps:

1. Use either the [`kendoMultiSelectTreeHierarchyBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreehierarchybindingdirective) or [`kendoMultiSelectTreeFlatBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreeflatbindingdirective) directive to implement automatic filtering.

2. Apply the [`kendoMultiSelectTreeExpandable`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/dropdowntreesexpanddirective) directive to enable expansion control.
   ```HTML
   <kendo-multiselecttree
       [kendoMultiSelectTreeHierarchyBinding]="data"
       [filterable]="true"
       kendoMultiSelectTreeExpandable
       ...
   >
   </kendo-multiselecttree>
   ```

3. Configure the [`expandOnFilter`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/dropdowntreesexpanddirective#expandonfilter) input provided by the expandable directive with your desired settings.
   ```HTML
   <kendo-multiselecttree
       [kendoMultiSelectTreeHierarchyBinding]="data"
       [filterable]="true"
       kendoMultiSelectTreeExpandable
       [expandOnFilter]="filterExpandSettings"
   >
   </kendo-multiselecttree>
   ```
   ```TypeScript
   // Limit automatic expansion to four results to keep filtering responsive.
   public filterExpandSettings: FilterExpandSettings = {
       maxAutoExpandResults: 4,
       expandMatches: true
   };
   ```

You can customize the auto-expanding behavior through several configuration options. The following sub-sections demonstrate different settings that you can apply to control when and how nodes expand during filtering operations:

* [Setting the Maximum Number of Expanding Items](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/multiselecttree/filtering#setting-the-maximum-number-of-expanding-items)
* [Expanding the Matching Items](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/multiselecttree/filtering#expanding-the-matching-items)
* [Persisting the Expanded Item State](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/multiselecttree/filtering#persisting-the-expanded-item-state)

### Setting the Maximum Number of Expanding Items

Use the [`maxAutoExpandResults`](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/api/filterexpandsettings#maxautoexpandresults) setting to prevent performance issues when filtering large datasets. This setting defines the maximum number of items that will be auto-expanded during filtering operations.

When the filter results exceed this threshold, the component will revert to the expanded state defined by the [`expandedOnClear`](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/api/filterexpandsettings#expandedonclear) setting, helping maintain optimal performance.

The following example demonstrates how to set the `maxAutoExpandResults` limit and observe how the auto-expansion behavior changes when the threshold is exceeded.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/multiselecttree/filtering/max-auto-expand/source.txt)

### Expanding the Matching Items

The [`expandMatches`](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/api/filterexpandsettings#expandmatches) setting controls whether matching items themselves are expanded to show their children. When enabled, this setting expands not only the parent nodes leading to matches, but also the matching nodes themselves, revealing their child items.

This option is only available in [`lenient`](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/api/treeviewfiltersettings#mode) filtering mode, as [`strict`](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/api/treeviewfiltersettings#mode) mode only displays exact matches without their children.

The following example demonstrates the `expandMatches` setting, which expands matched nodes to reveal their child items during filtering.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/multiselecttree/filtering/expand-matches/source.txt)

### Persisting the Expanded Item State

The [`expandedOnClear`](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/api/filterexpandsettings#expandedonclear) setting determines which nodes remain expanded when the filter is cleared or when filter results exceed the [`maxAutoExpandResults`](https://www.telerik.com/kendo-angular-ui-develop/components/treeview/api/filterexpandsettings#maxautoexpandresults) limit. This setting helps maintain a consistent user experience by controlling whether the tree returns to its original expanded state or maintains some level of expansion for better navigation.

The following example demonstrates the `expandedOnClear` setting that determines which nodes remain expanded when the filter is cleared or when the auto-expand limit is exceeded.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/multiselecttree/filtering/expanded-on-clear/source.txt)

## Manual Filtering

For more complex filtering requirements or when working with manual data-binding scenarios using the [`fetchChildren`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreecomponent#fetchchildren) and [`hasChildren`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreecomponent#haschildren) functions, you can implement custom filtering logic by utilizing the relevant component's events and properties.

To implement manual filtering functionality, set the [`filterable`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreecomponent#filterable) property to `true`. When filtering is enabled, the component renders a filter input in the popup list. On every character input, the component triggers a [`filterChange`](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreecomponent#filterchange) event with the typed string value that you can use to filter the data source.

The following example demonstrates how to implement manual filtering functionality in the MultiSelectTree.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/multiselecttree/filtering/manual/source.txt)

## Suggested Links

* [API Reference of the MultiSelectTree](https://www.telerik.com/kendo-angular-ui-develop/components/dropdowns/api/multiselecttreecomponent)
