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

GridView - Differentiate Filtered clear clicked?

6 Answers 144 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Maximiliano
Top achievements
Rank 1
Veteran
Maximiliano asked on 16 Mar 2021, 08:09 AM

Hi,

we have a gridview and with this we have local filtering and sort, but in some columns we have implemented a custom filter.

The thing is when the user clicks on the "Clear Filter" we need to execute some other code, is there any way to differentiate that the user clicked on the "Clear Filter" button?

 

 

 

regards!

6 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 18 Mar 2021, 04:32 PM

Hi Maximiliano,

I have two suggestions in order to handle the clearing of the filters as you desire:

1) You can create a custom filtering control and overriding its OnClearFilter method which is fired right after the Clear Filters button is clicked:

    public class CustomFilterControl : FilteringControl
    {
        public CustomFilterControl(Telerik.Windows.Controls.GridViewColumn column) : base(column)
        {
        }

        protected override void OnClearFilter()
        {
            base.OnClearFilter();

            // custom logic
        }
    }

2) You can add a generic event handler for the Button.ClickEvent and check if the pressed button has a Name of "PART_ClearFilterButton":

        public MainWindow()
        {
            InitializeComponent();
            this.GridView.AddHandler(Button.ClickEvent, new RoutedEventHandler(OnButtonClick));
        }

        private void OnButtonClick(object sender, RoutedEventArgs e)
        {
            var btn = e.OriginalSource as Button;
            if (btn.Name == "PART_ClearFilterButton")
            {
                // custom logic
            }
        }

Please let me know if any of these two approaches would work for you.

Regards,
Dilyan Traykov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Maximiliano
Top achievements
Rank 1
Veteran
answered on 18 Mar 2021, 04:48 PM

Thanks Dilyan i will try that.

 

 

 

Regards!

0
Dilyan Traykov
Telerik team
answered on 19 Mar 2021, 06:30 PM

Hi Maximiliano,

Do let me know how this goes.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Maximiliano
Top achievements
Rank 1
Veteran
answered on 22 Mar 2021, 10:57 AM

hi,

 

i finally done it with the first option, but the clear triggers the radGridView_Filtered event...

is there any way to know if this filtered was triggered by the clear?

 

 

regards!

0
Dilyan Traykov
Telerik team
answered on 22 Mar 2021, 03:25 PM

Hi Maximiliano,

Indeed, it is expected for the Filtered event to be called in this scenario.

You can, however, add an extra property to your custom filtering control and check this in the Filtered event:

        private void GridView_Filtered(object sender, Telerik.Windows.Controls.GridView.GridViewFilteredEventArgs e)
        {
            var column = e.ColumnFilterDescriptor.Column;
            var customFilteringControl = column.FilteringControl as CustomFilterControl;
            if (customFilteringControl != null && customFilteringControl.IsClearingFilter)
            {
                MessageBox.Show("Clearing Filter");
            }
        }

And here's how you can set the IsClearingFilter property:

        protected override void OnClearFilter()
        {
            this.IsClearingFilter = true;
            base.OnClearFilter();
            this.IsClearingFilter = false;
            // custom logic
        }

For your convenience, I've also prepared a small sample project to demonstrate this in action.

Please have a look and let me know if a similar approach would work in your original application.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Maximiliano
Top achievements
Rank 1
Veteran
answered on 22 Mar 2021, 03:28 PM

Thanks a lot Dilyan... 

 

 

Tags
GridView
Asked by
Maximiliano
Top achievements
Rank 1
Veteran
Answers by
Dilyan Traykov
Telerik team
Maximiliano
Top achievements
Rank 1
Veteran
Share this question
or