This is a migrated thread and some comments may be shown as answers.

Create custom Expression for FilterDescriptor

2 Answers 444 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yavor
Top achievements
Rank 1
Yavor asked on 13 May 2010, 08:07 AM

I need to be able to filter the RadGridView based on a collection property on each item. Here is a sample to illustrate my case. Let’s suppose that each item in the grid is of type Person and each person has a collection property ScheduledMeetings. I need to apply some kind of filter that does the following:

People.Where(p => p. ScheduledMeetings.Contains(someMeeting))

which will return all people participating in the specified meeting.

The documentation samples all use the built-in CreateFilterExpression method of the FilterDescriptor class. So my first choice was to use the existing FilterDescriptor class in combination with FilterOperator.Contains but it seems that ‘Contains’ only works with strings and not with IEnumerable (even with FilterDescriptor.MemberType specified)!

 I suppose I need to implement some custom FilterDescriptor class inheriting from FilterDescriptorBase and then provide the Expression from the CreateFilterExpression override. But how do I create such expression?

2 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 13 May 2010, 08:27 AM
Hi Yavor,

You can use the PredicateFilterDescriptor used in this blog post.

Regards,
Stefan Dobrev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Todor
Top achievements
Rank 1
answered on 14 May 2010, 12:50 PM
Thanks Stefan,

The PredicateFilterDescriptor really helped. This approach allows for direct use of predicates instead of creating the expression tree indirectly with the CompositeFilterDescriptor which is extremely more flexible and powerful!!

The referenced blog entry is excelent as well! 
Tags
GridView
Asked by
Yavor
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Todor
Top achievements
Rank 1
Share this question
or