Enabling Optional Filtering on Grid

2 posts, 1 answers
  1. ColinBowern
    ColinBowern avatar
    51 posts
    Member since:
    Aug 2012

    Posted 02 Apr 2010 Link to this post

    I have looked at several posts in the forum regarding filtering.  I want to achieve the following objective:

    • On load if there is no filter value (populated from state) the filter row is hidden and the filter button in the command toolbar is toggled off
    • On load if there is a filter value (populated from state) the filter row is show and the filter button in the command toolbar is toggled on
    • If the filter button is toggled on, show the filter row (preferably on client-side rather than AJAX round trip)
    • If the filter button is toggled off, clear all filters, hide the filter row, and rebind the grid

    I have been able to manage the display of the filter row using the ItemCreated event:
    if (e.Item is GridFilteringItem && string.IsNullOrEmpty(Grid.MasterTableView.FilterExpression)) 
        e.Item.Display = false
    else if (e.Item is GridCommandItem && !string.IsNullOrEmpty(Grid.MasterTableView.FilterExpression)) 
        var toolBar = e.Item.FindControl("ToolBar"as RadToolBar; 
        (toolBar.FindButtonByCommandName("Filter"as RadToolBarButton).Checked = true

    On the client side it sort-of works, but there is some odd behavior:
    function ToolBar_ClientButtonClicked(sender, args) 
        var button = args.get_item(); 
        switch (button.get_commandName()) 
            case 'Filter'
                if (button.get_isChecked()) 
                    $find('<%= Grid.ClientID %>').get_masterTableView().showFilterItem(); 
                    var masterTableView = $find("<%= Grid.ClientID %>").get_masterTableView(); 
                    masterTableView.filter("Description""", Telerik.Web.UI.GridFilterFunction.NoFilter); 
                    masterTableView.filter("Class""", Telerik.Web.UI.GridFilterFunction.NoFilter); 
                    masterTableView.filter("DefaultCategory""", Telerik.Web.UI.GridFilterFunction.NoFilter); 

    I have to click the filter button three times to get it to show the row (turn on, turn off, turn on and then I see the row).  If I use jQuery to hide the .rgFilterRow class it works fine.

    The calls to clear the filter appear to generate individual post-backs where I want one call to clear everything.  One thought was to use fireCommand and do the clean-up on the server side.  In either case I also want to only make the callback if the filter has a value in it (if the results aren't currently filtered there is no point in round tripping).

  2. Answer
    Yavor avatar
    11 posts

    Posted 08 Apr 2010 Link to this post

    Hi ColinBowern,

    You can clear the whole expression on the server by using "RadGrid1.MasterTableView.FilterExpression". Additionally, with respect to hiding the filter item. To make sure that the application behaves consistently, it is best to handle the logic in one place only - for example on the client, instead of setting the value on the server, and the showing the filtering item via client side code. You can use a hidden input, which can serve as a flag, indicating whether the filter item should be hidden. Then, in the GridCreated client side event handler, you can hide the filter as needed.
    I hope this suggestion helps.

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