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

Clear all filters - programmatically

9 Answers 1710 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 21 Apr 2011, 08:33 PM
How I can programmatically clear all filters that have been manually set using the built in 'column' filters?
I want to add a 'CLEAR FILTERS' button.
thx again

9 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 21 Apr 2011, 08:54 PM
Hello Jon,

 

You may clear RadGridView's FilterDescriptors through calling the Clear method.


All the best,
Vanya Pavlova
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
Jon
Top achievements
Rank 1
answered on 21 Apr 2011, 08:59 PM
What do I call clear on?
0
Accepted
Vanya Pavlova
Telerik team
answered on 21 Apr 2011, 09:06 PM
Hello Jon,

 
You need to attach to the button's click event and clear the FilterDescriptors collection, as shown below:

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.playersGrid.FilterDescriptors.Clear();
        }

Kind regards,
Vanya Pavlova
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
Jon
Top achievements
Rank 1
answered on 21 Apr 2011, 09:20 PM
THX
0
Guy
Top achievements
Rank 1
answered on 06 Jul 2012, 08:56 PM
This is not a proper solution in my case. I want a button Clear All that clears filters on all columns, but if I clear the FilterDescriptors collection, the Filter PopUp do not reflect the changes.

1) Check a checkbox in the Filter PopUp to filter on checked element
2) Press Clear All button and do: this.playersGrid.FilterDescriptors.Clear();
3) Filter icon is still yellow (indicating we are still filtering) and if you click on the Filter icon, the element is still checked as if it was filtered. Note that this actually shows a false information to the user, because the Filter has been removed, but it is not reflected.

How can I do a Clear All on the filters that reflects inside of the Filter PopUps?

Thank You
0
Arun
Top achievements
Rank 1
answered on 03 Jun 2014, 10:44 AM
In my case it is not working:

Code:
MyGrid.FilterDescriptors.Clear();
MyGrid.Rebind();

the filter icon is still there..




0
Dimitrina
Telerik team
answered on 03 Jun 2014, 10:57 AM
Hello,

You should clear the filters like so:
this.radGridView.FilterDescriptors.SuspendNotifications();
foreach (Telerik.Windows.Controls.GridViewColumn column in this.radGridView.Columns)
{
    column.ClearFilters();
}
this.radGridView.FilterDescriptors.ResumeNotifications();

The filtering concept is described in details in the Basic Filtering topic.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Arun
Top achievements
Rank 1
answered on 03 Jun 2014, 11:16 AM
Thanks it works ,
but in case of Custom Filtering Control inherited from " IFilteringControl " it still shows the filter icon..
i have a Dependency property:
 public static readonly DependencyProperty IsActiveProperty =
            DependencyProperty.Register("IsActive", typeof(bool), typeof(FilterId), new PropertyMetadata(false));
public bool IsActive
        {
            get { return (bool)GetValue(IsActiveProperty); }
            set { SetValue(IsActiveProperty, value); }
        }
but i cant update this from other usercontrols.
0
John
Top achievements
Rank 1
Iron
answered on 16 Sep 2016, 08:34 PM

Just in case anyone would find this useful:

 

public void Prepare(Telerik.Windows.Controls.GridViewColumn columnToPrepare)        {            _column = columnToPrepare;            CollectionChangedEventManager.AddHandler(_column.DataControl.FilterDescriptors, FilterDescriptors_CollectionChanged);            IFilterDescriptor f = _column.DataControl.FilterDescriptors.OfType<FilterDescriptor>().FirstOrDefault(p => p.Member == "Readiness");            if (f == null)                f = _column.DataControl.FilterDescriptors.OfType<CompositeFilterDescriptor>().FirstOrDefault(p => p.FilterDescriptors.OfType<FilterDescriptor>().Any(v => v.Member == "Readiness"));            var l = new List<FilterDescriptor>();            if (f is CompositeFilterDescriptor)            {                l.AddRange((f as CompositeFilterDescriptor).FilterDescriptors.Cast<FilterDescriptor>());            }            else if (f is FilterDescriptor)                l.Add((f as FilterDescriptor));            IsActive = f != null;            foreach (var cb in this.FindVisualChild<Grid>().FindVisualChildren<CheckBox>())            {                if (f == null)                    cb.IsChecked = false;                else                {                    cb.IsChecked = (cb == production && l.Any(fd => (ReadinessState)fd.Value == ReadinessState.PRODUCTION))                        || (cb == development && l.Any(fd => (ReadinessState)fd.Value == ReadinessState.DEVELOPMENT));                }            }        }

 

private void FilterDescriptors_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)        {            var coll = sender as ObservableCollection<IFilterDescriptor>;            IFilterDescriptor f = coll.OfType<FilterDescriptor>().FirstOrDefault(p => p.Member == "Readiness");            if (f == null)                f = coll.OfType<CompositeFilterDescriptor>().FirstOrDefault(p => p.FilterDescriptors.OfType<FilterDescriptor>().Any(v => v.Member == "Readiness"));            CollectionChangedEventManager.AddHandler(coll, FilterDescriptors_CollectionChanged);            var l = new List<FilterDescriptor>();            if (f is CompositeFilterDescriptor)            {                l.AddRange((f as CompositeFilterDescriptor).FilterDescriptors.Cast<FilterDescriptor>());            }            else if (f is FilterDescriptor)                l.Add((f as FilterDescriptor));            IsActive = f != null;        }

 

 

 

Tags
GridView
Asked by
Jon
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Jon
Top achievements
Rank 1
Guy
Top achievements
Rank 1
Arun
Top achievements
Rank 1
Dimitrina
Telerik team
John
Top achievements
Rank 1
Iron
Share this question
or