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

Reset Column Filter Function

2 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 12 Aug 2010, 03:51 PM
I have a column in my RadGrid whose visibility is dependant on a checkbox on the page. When the user checks the checkbox, the column appears. When they uncheck, it disappears. Both the checkbox and the grid are in an ajax panel. Works fine.

My problem is when the user sets a filter for the column in question and then unchecks the checkbox, the filter persists. It's not apparent to the user that data is being filtered because the column with the filter is no longer visible.

So I want to reset the column filter when the user toggles the visiblity of the column. To do this, I have the following code in my checkbox's CheckChanged event handler:

if(chkShowInActive.Checked)
{
    myGrid.Columns.FindByUniqueName("IsActive").Visible = true;
}
else
{
    myGrid.Columns.FindByUniqueName("IsActive").Visible = false;
}
  
myGrid.Columns.FindByUniqueName("IsActive").CurrentFilterFunction = GridKnownFunction.NoFilter;
myGrid.Rebind();

This doesn't seem to have any effect. The grid still filters the data. What am I doing wrong?

2 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 17 Aug 2010, 08:35 AM
Hi Robert,

If you need to persist the filter so that the grid data is filtered by this column, or, contrary, remove the filter and show all filter data, it is not enough to only set the column filter and function. You have to fire a filter command also:

GridColumn isActiveColumn = myGrid.MasterTableView.GetColumnSafe("IsActive");
isActiveColumn.Visible = chkShowInActive.Checked;
isActiveColumn.CurrentFilterFunction = GridKnownFunction.NoFilter;
 
//get the GridFilteringItem and fire a filter command that will
//clear the filter for that column. Note: do not call Rebind() explicitly
//after the command - the grid will rebind automatically.
GridItem filterItem = myGrid.MasterTableView.GetItems(GridItemType.FilteringItem)[0];
filterItem.FireCommandEvent(RadGrid.FilterCommandName, new Pair("NoFilter", "IsActive"));


Best wishes,
Veli
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
Robert
Top achievements
Rank 1
answered on 17 Aug 2010, 02:50 PM
Worked like a charm. Thanks.
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Veli
Telerik team
Robert
Top achievements
Rank 1
Share this question
or