Overview
Filtering allows users to view a subset of data based on criteria. There are three ways for a user to filter:
- Single-column filtering: Clicking the "Filter" option from the feature menu when the column has opted into filtering.
- Multi-column filtering: Following option 1 for any additional column
- Global filtering: Utilizing the
setGlobalFilteraction from the Data Grid Context.
Active Actions
Once a filter is active, the user can:
- Edit filters: Clicking the added "Edit filter" icon button that displays in the column header that has the active filter.
- Clear filters: Clicking the "Clear Filter" option in the column feature menu.
Implementing column filtering
You must opt-in to column filtering by setting the features.filter prop to true or passing in a custom filter function. Doing so will display the filter option in the column menu.
Multi-column Filtering
Multi-column filtering is enabled by default. The user simply selects another column to filter in addition to any other column that is actively filtered.
Global Filtering
You can globally filter the Grid by utilizing the setGlobalFilter action in any slot component you provide.
In this example, we create a custom Toolbar that filters the grid globally on input.
Custom Comparator
A comparator determines how two cell values should be filtered. The default comparator uses the vanilla JavaScript basic comparison from the Operator provided.
To provide a custom comparator, you can pass a function as the features.filter option.
The snippet below is the same comparator we are using for all the demos on this page.
Operators
The Data Grid provides an OPERATORS constant which is used to ensure consistency across any filter-based approach you may use.
Options
The filter feature accepts either a boolean or a custom filter function that provides the following arguments:
| Params | Type | Description |
|---|---|---|
row | TData | The row of the grid comparing the filter. |
columnId | string | The columnId the filter is applied to. |
filterValue | unknown | The value provided to the filter. |