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

Enabling Optional Filtering on Grid

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ColinBowern
Top achievements
Rank 1
ColinBowern asked on 02 Apr 2010, 09:16 PM
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(); 
            } 
            else 
            { 
                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); 
                masterTableView.hideFilterItem(); 
            } 
            break
    } 

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).

Thoughts?

1 Answer, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 08 Apr 2010, 06:29 AM
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.

Regards,
Yavor
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.
Tags
Grid
Asked by
ColinBowern
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or