Remove Header Context Menu Filter Programatically

3 posts, 0 answers
  1. Glenn Boothe
    Glenn Boothe avatar
    21 posts
    Member since:
    Jul 2008

    Posted 13 Jul 2010 Link to this post

    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. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 15 Jul 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Glenn Boothe
    Glenn Boothe avatar
    21 posts
    Member since:
    Jul 2008

    Posted 15 Jul 2010 Link to this post

    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
Back to Top