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

FilterDescriptorCollection using OR

2 Answers 190 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joel Palmer
Top achievements
Rank 2
Joel Palmer asked on 06 May 2011, 12:23 AM

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 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 06 May 2011, 08:33 AM
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
0
gans
Top achievements
Rank 1
answered on 07 Feb 2013, 09:49 PM
Is the FilterSettings Deprecated? I don't see it in the RadTreeListView and also in RadGridView. 
Tags
GridView
Asked by
Joel Palmer
Top achievements
Rank 2
Answers by
Rossen Hristov
Telerik team
gans
Top achievements
Rank 1
Share this question
or