FilterDescriptorCollection using OR

3 posts, 0 answers
  1. Joel Palmer
    Joel Palmer avatar
    175 posts
    Member since:
    May 2009

    Posted 05 May 2011 Link to this post

    I have a DataGrid that needs to be filtered programatically.  I populate the dependency grid with a ItemsSource with all my data in it.  When I select an item in a parent grid, I want this grid to filter showing the one or many dependency items. 

    So, I'd figured out I can clear the FilterDescriptorCollection and add items to it in using this syntax.  Note FilterSettings = FilterDescriptorCollection:

    aggregationGridView.FilterSettings.Clear();
    foreach (AggregateDD child in aggregate.ChildList)
    {
        FilterDescriptor filter = new FilterDescriptor(
             "AggregateID", FilterOperator.IsEqualTo, child.AggregateID);
        aggregationGridView.FilterSettings.Add(filter);
    }

    However, this seems to write a query that as AND instead of OR.  This is more the query I'd like to run:

    ( (AggregateID IsEqualTo 385 MC) OR (AggregateID IsEqualTo 386 MC) OR (AggregateID IsEqualTo 387 MC) OR (AggregateID IsEqualTo 388 MC) )

    How do I add a new FilterDescriptor to the FilterDescriptorCollection as an OR?

    Thanks for your help.

  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 06 May 2011 Link to this post

    Hello Joel Palmer,

    There is a special filter descriptor called CompositeFilterDescriptor. It combines one or more "normal"  filter descriptors with a logical operator of AND/OR. So you can do the following:

    var compositeFilter = new CompositeFilterDescriptor();
    compositeFilter.LogicalOperator = FilterCompositionLogicalOperator.Or;
    foreach (AggregateDD child in aggregate.ChildList)
    {
        FilterDescriptor filter = new FilterDescriptor(
             "AggregateID", FilterOperator.IsEqualTo, child.AggregateID);
        compositeFilter.FilterDescriptors.Add(filter);
    }
    aggregationGridView.FilterSettings.Add(compositeFilter);

    With the help of this CompositeFilterDescriptor you can create N-level hierarchies of filters, i.e. trees of filters.

    I hope this helps. Let me know if there are problems.


    All the best,
    Ross
    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. gans
    gans avatar
    48 posts
    Member since:
    Jan 2012

    Posted 07 Feb 2013 Link to this post

    Is the FilterSettings Deprecated? I don't see it in the RadTreeListView and also in RadGridView. 
Back to Top