The Grid component offers built-in support for filtering.
To enable filtering, set the grid's
FilterMode property to one of the following values:
Telerik.Blazor.GridFilterMode.FilterRow- a row of filter options is rendered below the column headers
Telerik.Blazor.GridFilterMode.FilterMenu- the column headers render a button that shows a popup with filtering options
The behavior of the filter input and the available filter operators will depend on the column data type. For example, a boolean field will only have the options "is true" and "is false" and will not have operators like "contains" or "greater than".
You can filter more than one column at a time, and all filter rules will be applied together with an
You can prevent the user from filtering a certain field by setting
Filterable="false" on its column.
In addition to the two main filtering modes, the grid offers two more features that can enhance the user experience when looking for data:
A searchbox in the toolbar can amend the filters and let the user look up many fields at once
The filter menu can show a list of checkboxes with the distinct values from the data to make filtering resemble Excel.
There are two approaches to customize the grid filtering behavior, and you can use them together:
Perform the data operations yourself (e.g., by outsourcing them to some API backend or other service) - to do that, use the
OnReadevent. This will let you fetch only the current page of data for the grid, instead of pulling the entire data set and storing it in-memory in the view-model.
Customize the appearance and behavior of the filters - for that, use the Filter Templates the grid provides.
The following articles and sample projects can be helpful when implementing filtering:
Capture Filtered event - the grid state lets you know when it changes so you can capture different aspects of the change
Server Filtering - this article explains how to implement manual data source operations so you can offload the work to the server. It provides the overview of how to setup the grid for that, and examples - several with local data and links a repository with examples using REST API endpoints.
- The grid uses
Activator.CreateInstance<TItem>();to get the type of the item it is bound to in order to generate proper filters and filter operators for them. Thus, the Model should have a Parameterless constructor defined.