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

Thanks Dilyan i will try that.
Regards!
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/.

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!
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/.

Thanks a lot Dilyan...