Clear all filters - programmatically

10 posts, 1 answers
  1. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 21 Apr 2011 Link to this post

    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
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 21 Apr 2011 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 21 Apr 2011 Link to this post

    What do I call clear on?
  5. Answer
    Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 21 Apr 2011 Link to this post

    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
  6. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 21 Apr 2011 Link to this post

    THX
  7. Guy
    Guy avatar
    46 posts
    Member since:
    Nov 2008

    Posted 06 Jul 2012 Link to this post

    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
  8. Arun
    Arun avatar
    2 posts
    Member since:
    Jun 2014

    Posted 03 Jun 2014 Link to this post

    In my case it is not working:

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

    the filter icon is still there..




  9. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 03 Jun 2014 Link to this post

    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.
     
  10. Arun
    Arun avatar
    2 posts
    Member since:
    Jun 2014

    Posted 03 Jun 2014 in reply to Dimitrina Link to this post

    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.
  11. John
    John avatar
    17 posts
    Member since:
    Aug 2014

    Posted 16 Sep in reply to Arun Link to this post

    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;        }

     

     

     

Back to Top
UI for WPF is Visual Studio 2017 Ready