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

setting filter menu selection after rebind

1 Answer 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Albert Shenker asked on 07 Jun 2011, 12:26 PM
I have implemented Filtering in my RadGrid, however, the filtering is done at the database, not by the Grid Control. Therefore I handle the Grid ItemCommand event, check for the Filter Command, build a filter string based on the filterPair, cancel the filter command and rebind the grid with the filterstring. Everything works fine except I have noticed a couple issues:

1) After the grid is rebound, if I click on the filtermenu icon, the "NoFilter" item is selected, even though the grid was filtered with some other selection (such as "StartsWith"). I assume this is because I set e.cancelled = true in the ItemCommand event. Is there a way to set the proper selected filter menu item after the grid is rebound? In the ItemCommand Event, I store the various column filter selections in viewstate, so I believe, If I am able to access the filter menu somehow, I should be able to set the right value (hopefully without firing another filter event)

2) When simple filtering is used and the user selects the "NoFilter" option to remove the filter, the text value they specified is cleared. This doesn't occur in my scenarion, and again I assume it is because I set e.cancelled = true in the ItemCommand event.. I tried adding the following to the ItemCommand Event handler:

Dim txtBox As TextBox = CType((CType(e.Item, GridFilteringItem))(filterPair.Second).Controls(0), TextBox)
                               If filterPair.First.ToString = "NoFilter" Then
                                   txtBox.Text = String.Empty
                               End If

What happens is, the filter value disappears for a moment, but then returns when the grid is finsihed rebinding. Is there a way to clear this text if the "NoFilter" option is selected?

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 10 Jun 2011, 01:46 PM
Hello Albert,

You could set CurrentFilterFunction for the column before rebinding the grid using the new data.

Here is an example:
GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("YourColumn");
column.CurrentFilterFunction = GridKnownFunction.Contains;
About you second issue, try to set column.CurrentFilterValue = "" to clear the filtered value.

Also check this help topic: http://www.telerik.com/help/aspnet-ajax/grid-applying-default-filter-on-initial-load.html

Best wishes,
Vasil
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Answers by
Vasil
Telerik team
Share this question
or