New to Telerik UI for ASP.NET Core? Start a free 30-day trial
Use MultiSelect as Filter in Grids
Environment
Product |
Telerik UI for ASP.NET Core MultiSelect, Telerik UI for ASP.NET Core Grid |
Product Version | Created with version 2024.4.1112 |
Description
How can I use the MultiSelect as a filter in the default column filter menu of the Grid?
Solution
- Remove the second filter input in the default column filter menu using the
Extra(false)
option of theFilterable
configuration. - Use the
UI
option of theFilterable
configuration and pass the name of the JavaScript function (multiselectFilter
) that will create the MultiSelect. - Within the
multiselectFilter
function, initialize the MultiSelect editor and remove the default DropDownList editor with jQuery. Also, handle thesubmit
event of the column filter menu, prevent its default action, and filter the Grid based on the selected options in the MultiSelect. - The Grid is configured for remote data binding, and all data operations are performed server-side. As a result, when you call the
filter()
method of the DataSource, the filter expression will be sent to the server. Intercept the applied filters through therequest
object and filter the data as demonstrated in theRead
action in the code snippet below.
Razor
@(Html.Kendo().Grid<ViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(e => e.ID);
columns.Bound(e => e.Tags).Filterable(filterable => filterable.Extra(false)
.Messages(m=> m.Info("Show items with value that contains"))
.UI("multiselectFilter")
)
.ClientTemplate("#:Tags.join(',')#");
})
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Read", "Home"))
)
)
For the complete implementation of how to use the MultiSelect as a filter in a specified Grid column, refer to the ASP.NET MVC application in the UI for ASP.NET MVC Examples repository. You can use this application as a starting point to configure the same behavior in an ASP.NET Core project.