Last Updated: 08 Mar 2024 00:45 by alex
Created on: 01 Mar 2024 02:21
Category: UI for Blazor
Type: Feature Request
Ability to pass a cutom Function to the FilterDescriptor

Sometimes we need custom filter logic. 

The advised approach currently is to use the OnRead event and have to manage the fetching of data manually  https://docs.telerik.com/blazor-ui/components/grid/manual-operations

If we could set a column to use a filter function  that has Func<GridDataType, Bool>? then we could apply this complex filter without having to repeatedly query the database and apply filters server side. 

For example, if I wanted to filter a column that related to an object that had a property that was a Collection<T> I could check the values of this collection against a filter UI I have made somewhere in the grid or outside of it. Then when the columns filterdescriptior was reviewed it would check my Func which returned True if any of the Rows Collection<T> matched my custom filter UI options.

Example use case that this feature would allow; 

Posted on: 08 Mar 2024 00:45
I am just suggesting a feature that was available in MudBlazor. The ability to apply a filter by a function. 
This is because filter template still requires you to define the filter in a restricted way to columns and setting OR or AND. 


Whereas being able to simple run your own code and return YES filter this row as per by function. 
Nadezhda Tacheva
Posted on: 07 Mar 2024 11:43

Hi Alex,

In your private ticket we discussed a possible solution similar to the one listed here: Filter a Grid Column that is a List.

Generally speaking, the requested feature is valid but it will not cover your use case. The main reason is that you are targeting a column that contains a collection of items. By design, the Grid will render the built-in filter editors only for the column whose FIeld parameters use primitive types.

The Grid will not render a filter menu or an editor in the filter row for the column that contains the list of items. This means that if you need to enable the filtering for this column, you will have to use a Filter Template.

Once the Filter Template is used, the Grid no longer handles the filtering. In this case, it is up to the application to perform the filtering logic. This gives you full flexibility to control how the filtering will happen, so I am not certain what will be the purpose of passing a Function to the FilterDescriptor. Moreover, the FilterDescriptor only supports primitive types for its MemberType field.

Another key point in this scenario is that there is no built-in provision in .NET to filter a collection based on the contents of another collection. Thus, you will need to build a custom filtering logic anyway.

Having the above in mind, I will keep the request to track the interest for the ability to pass a custom Function to the FilterDescriptor. However, for your scenario, the filtering has to be handled with a custom approach as per the linked example.

Nadezhda Tacheva
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!