Hello folks,
I need to track the currently selected column filters.
Firstly, I attach the DataFiltered event to my webdatagrid like so:
dtPlanningWin10Migration.Behaviors.Filtering.DataFiltered += Filtering_DataFiltered;
In the event I save the filters after the grid data have been filtered:
private void Filtering_DataFiltered(object sender, FilteredEventArgs e) { ColumnFilters CurrentGridColumnFilters = e.ColumnFilters; }
Here I store all filters that are currently selected by the user.
The issue is that if a user clicks on "Clear filter" in the filter options of the grid, the column is still present in the e.ColumnFilters list. Why hasn't it been removed automatically from the list? How can I detect if the filter column has been cleared or not?
Thanks and all the best,
Flo
Hello Flo,
Thank you for contacting Infragistics Support.
When you click "Clear filter", what you get in e.ColumnFilters is one filter with RuleType "All" and an empty value. Basically this means the filter is cleared.
If you want to check whether the filters are cleared, here is the code:
protected void WebDataGrid1_DataFiltered(object sender, FilteredEventArgs e) { WebDataGrid wdg = sender as WebDataGrid; ColumnFilter cf = e.ColumnFilters.GetFilter("ProductName"); RuleTextNode rtn = (cf.Condition as RuleTextNode); TextFilterRules rule = rtn.Rule; string vl = rtn.Value; if (rule == TextFilterRules.All && vl == string.Empty) { // the col filter is clear } }
Here is a sample as well - link.
Please let me know if you need further help.
Hello Tihomir,
thanks for your help. Is there any specific reason why the column isn't removed from the collection after clicking on "Clear Filter"? To be honest, it makes checking of cleared columns quite cumbersome.
All the best,
I am not aware of any specific reason why this behavior is implemented in that way. The important part is this behavior is consistent, reliable and you'll accomplish your goal by using it.