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

Applying multiple column filters with the OR logical operator between them

5 Answers 703 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 25 Jul 2013, 09:40 AM
Hi guys,
As the title states, I'm trying to apply the OR logical operator between multiple column filters instead of the default AND operator that is applied when using the popup UI of the GridView.
I haven't found any simple way of doing this without attaching a DataFilter to the grid, and we do not like the UI of the DataFilter.
What I did come up with is handling the Sorted event and iterating over the columns to get their filters and add them to a compound filter like so:
Telerik.Windows.Data.CompositeFilterDescriptor mainFilter = new Telerik.Windows.Data.CompositeFilterDescriptor();
mainFilter.LogicalOperator = Telerik.Windows.Data.FilterCompositionLogicalOperator.Or;
this.dgTaskManager.FilterDescriptors.SuspendNotifications();
foreach (Telerik.Windows.Controls.GridViewColumn column in this.dgTaskManager.Columns)
{
    //Add all active column filters to the main filter
    if (column.ColumnFilterDescriptor.IsActive)
    {
        mainFilter.FilterDescriptors.Add(column.ColumnFilterDescriptor);
        this.filteredColumnList.Add(column);
    }
}
this.dgTaskManager.FilterDescriptors.Clear();
this.dgTaskManager.FilterDescriptors.Add(mainFilter);
this.dgTaskManager.FilterDescriptors.ResumeNotifications();

This works fine in terms of filtering correctly, but the funnel icon of the filtered columns is obviously unaffected since the FilterDescriptors collection of the grid no longer holds the filtered columns directly.
I tried manually setting each filtered column's FilterControl and setting its isActive property to true after ResumeNotifications(), but for some reasons it only highlights the last filtered column's funnel and only after opening and closing the filter control of the other filtered columns does it update their funnel's highlighting correctly. In addition it also doesn't seem to handle removing filters correctly (in terms of UI).
Does anyone have an idea how to achieve this? I can't believe that the need to apply the OR operator between columns hasn't arisen before me, am I missing something obvious?
Thanks
Orr

5 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 25 Jul 2013, 10:00 AM
Hi,

Please, do this:

this.grid.FilterDescriptors.LogicalOperator = FilterCompositionLogicalOperator.Or;


I hope this helps.

Regards,
Rossen Hristov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Michael
Top achievements
Rank 1
answered on 25 Jul 2013, 10:28 AM
Thank you very much for the quick response, I feel really stupid for not seeing this obvious solution from the start.
Is there any built in selector of the GridView UI to control this property or do I need to bind it to my own control?
0
Rossen Hristov
Telerik team
answered on 25 Jul 2013, 10:33 AM
Hello,

We don't have a built-in UI for controlling this. But you can place a very simple widget anywhere in the grid's control template to control this property. This applies for all the other hundreds of RadGridView properties as well. 

Regards,
Rossen Hristov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Stephen
Top achievements
Rank 1
answered on 07 Jul 2016, 03:06 PM

Is there a simple example of this I could reference? 

How would this be implemented?

this.grid.FilterDescriptors.LogicalOperator = FilterCompositionLogicalOperator.Or;

0
Dilyan Traykov
Telerik team
answered on 12 Jul 2016, 07:55 AM
Hello Stephen,

Please refer to the Programmatic Filtering article of our documentation, and more specifically - its CompositeFilterDescriptor section for a good example of how to construct unlimited filtering criteria trees.

If you would, however, like to change the logical operator between the two field filters with a ColumnFilterDescriptor as though the user had done this through the filtering popup UI, you can have a look at the Filtering Single Column section of the same article.

I hope you find this helpful.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Michael
Top achievements
Rank 1
Stephen
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or