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

Clear Filters programmatically

1 Answer 88 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Heiko
Top achievements
Rank 1
Iron
Veteran
Heiko asked on 08 Apr 2016, 03:35 PM

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())
02.{
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.    }
12.}

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??

Regards
Heiko

1 Answer, 1 is accepted

Sort by
0
Heiko
Top achievements
Rank 1
Iron
Veteran
answered on 08 Apr 2016, 04:00 PM

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())
3.{
4.    foreach (IColumnFilterDescriptor filterCondition in columnFilters)
5.    {
6.        filterCondition.Clear();
7.    }
8.}

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

Tags
GridView
Asked by
Heiko
Top achievements
Rank 1
Iron
Veteran
Answers by
Heiko
Top achievements
Rank 1
Iron
Veteran
Share this question
or