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

Remove Header Context Menu Filter Programatically

2 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Glenn Boothe
Top achievements
Rank 1
Glenn Boothe asked on 13 Jul 2010, 12:10 PM
I'm trying to remove a filter set in the header context menu of a RadGrid like so:

For Each gc As GridColumn In dtgCorp.MasterTableView.Columns
    With gc
        If .IsBoundToFieldName(strRemoveFilter) Then
            .CurrentFilterFunction = GridKnownFunction.NoFilter
            .CurrentFilterValue = ""
            .AndCurrentFilterFunction = GridKnownFunction.NoFilter
            .AndCurrentFilterValue = ""
        End If
    End With
Next

dtgCorp.Rebind()

This will update the actual drop downs and text boxes in the header context menu filter of the column I'm removing the filter for, but it will not actually reevaluate the grid's new FilterExpression, leaving the data filtered with the 'removed' filter.

Is there a way to invoke the grid's filter command or something, and refresh its FilterExpression?

2 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 15 Jul 2010, 02:42 PM
Hi Glenn,

You need to following code:

For Each gc As GridColumn In dtgCorp.MasterTableView.Columns
    With gc
        If .IsBoundToFieldName(strRemoveFilter) Then
            RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0].FireCommandEvent(RadGrid.HeaderContextMenuFilterCommandName, new Triplet("strRemoveFilter", new Pair(GridKnownFunction.NoFilter, ""), new Pair(GridKnownFunction.NoFilter, "")));
        End If
    End With
Next

In addition, the following help article should prove helpful:
http://www.telerik.com/help/aspnet-ajax/grdfirecommandeventfromcode.html

All the best,
Tsvetoslav
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
Glenn Boothe
Top achievements
Rank 1
answered on 15 Jul 2010, 08:40 PM
Tsvetoslav,
That worked great! I had to make one minor change:

For Each gc As GridColumn In dtgCorp.MasterTableView.Columns
    With gc
        If .IsBoundToFieldName(strRemoveFilter) Then
            RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)(0).FireCommandEvent(RadGrid.HeaderContextMenuFilterCommandName, new Triplet("strRemoveFilter", new Pair("NoFilter", ""), new Pair("NoFilter", "")))
        End If
    End With
Next

It seems the RadGrid uses the string value "NoFilter", rather than the enum value GridKnownFunction.NoFilter. So to mimic the filter's Command Event exactly, I had to change that.

Thanks a ton!
Glenn
Tags
Grid
Asked by
Glenn Boothe
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Glenn Boothe
Top achievements
Rank 1
Share this question
or