Clear Filters programmatically

2 posts, 0 answers
  1. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 08 Apr 2016 Link to this post

    I have a GridView which is bound to a QueryableCollectionView. The QCV has some filterdescriptors added when created (like filtering on Customer_Id), but it is also possible to add more filter conditions through the UI of the GridView. My customer asked me to add a "Clear all filters" button which should clear all filters added via the UI on GridView. I wrote the following code to clear these filters (VehicleList is the QCV):

    01.using (this.VehicleList.DeferRefresh())
    03.    // get all filters added to the GridView and remove them
    04.    var columnFilterList = this.VehicleList.FilterDescriptors.OfType<MemberColumnFilterDescriptor>().ToList();
    05.    if (columnFilterList.Any())
    06.    {
    07.        foreach (MemberColumnFilterDescriptor filterCondition in columnFilterList)
    08.        {
    09.            this.VehicleList.FilterDescriptors.Remove(filterCondition);
    10.        }
    11.    }

    The result: all filter-icons on the GridView return to inactive. However, the checkboxes inside the filter-dropdown that have been used to declare the filter condition are still checked! How can I delete all filter conditions via code (it HAS to be done inside a ViewModel, I can not use the GridView directly) and have all checkboxes inside the filter-dropdown unselected??


  2. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 08 Apr 2016 in reply to Heiko Link to this post

    Just a few minutes later I found the solution. I have to take a list of "IColumFilterDescriptor" then use the "Clear()" method like that:

    1.var columnFilters = this.VehicleList.FilterDescriptors.OfType<IColumnFilterDescriptor>().ToList();
    2.if (columnFilters.Any())
    4.    foreach (IColumnFilterDescriptor filterCondition in columnFilters)
    5.    {
    6.        filterCondition.Clear();
    7.    }

    Really easy! Looking inside the Telerik Source Code helps. ;-)

Back to Top