Create custom Expression for FilterDescriptor

3 posts, 0 answers
  1. Yavor
    Yavor avatar
    19 posts
    Member since:
    Apr 2009

    Posted 13 May 2010 Link to this post

    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. Stefan Dobrev
    Stefan Dobrev avatar
    790 posts

    Posted 13 May 2010 Link to this post

    Hi Yavor,

    You can use the PredicateFilterDescriptor used in this blog post.

    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.
  3. Todor
    Todor avatar
    13 posts
    Member since:
    Nov 2008

    Posted 14 May 2010 Link to this post

    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! 
Back to Top