Applying multiple column filters with the OR logical operator between them

6 posts, 1 answers
  1. Ido
    Ido avatar
    2 posts
    Member since:
    Sep 2012

    Posted 25 Jul 2013 Link to this post

    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
  2. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 25 Jul 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ido
    Ido avatar
    2 posts
    Member since:
    Sep 2012

    Posted 25 Jul 2013 Link to this post

    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?
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 25 Jul 2013 Link to this post

    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 >>
  6. Stephen
    Stephen avatar
    1 posts
    Member since:
    Jul 2016

    Posted 07 Jul in reply to Rossen Hristov Link to this post

    Is there a simple example of this I could reference? 

    How would this be implemented?

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

  7. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 12 Jul Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready