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

clearing filters after search

5 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
golddog
Top achievements
Rank 1
golddog asked on 09 Sep 2008, 06:56 PM

We're displaying search results in a grid, and allowing filtering by column.

The issue I'm resolving is if a user filters, then hits the search button again, the results of the query are set as the data source, then the grid re-applies the filters on Rebind().

I want to clear the filters and show the data which the new search got from the database.

I found a thread which gave me something that works.  Rather than do all this work for every grid in our application, I was looking for something like grid.ClearFilters().

Am I just missing the easier way?  If not, that might be a nice convenience method.

Code-behind of my search button click:

------------
...set new search data...

grdUserSearchResults.MasterTableView.FilterExpression = String.Empty;
foreach (Telerik.Web.UI.GridColumn column in grdUserSearchResults.Columns)
{
    column.CurrentFilterFunction = Telerik.Web.UI.GridKnownFunction.NoFilter;
    column.CurrentFilterValue = String.Empty;
}

grdUserSearchResults.Rebind();
--------------

5 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 12 Sep 2008, 09:54 AM
Hello golddog,

Indeed this is the means to clear the previously applied filters for the grid when the data in the control is refreshed. Thank you for the suggestion for a shortcut method which takes care of this internally - I will forward it to our developers to be considered for the next versions of the product.

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Eric Skaggs
Top achievements
Rank 2
answered on 13 Oct 2009, 05:00 PM
Is this going to be implemented?  It doesn't look like it has been yet.

Thanks,

Eric Skaggs
0
Sebastian
Telerik team
answered on 14 Oct 2009, 12:12 PM
Hello Eric,

Indeed such shortcut is not implemented yet. At this point consider the solution discussed previously.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Eric Skaggs
Top achievements
Rank 2
answered on 14 Oct 2009, 02:57 PM
Hi Sebastian,

I definitely had attempted to use the "solution discussed previously," to no avail.  However, I did eventually find a solution to my problem.  My grid is set to automatically generate its columns; they are not defined in the markup.  Using that setup, the "solution discussed previously" was not a solution at all.  I had to modify the code as follows (I've updated the code that golddog presented earlier in this thread for readers' convenience):
grdUserSearchResults.MasterTableView.FilterExpression = String.Empty;  
foreach (Telerik.Web.UI.GridColumn column in grdUserSearchResults.MasterTableView.AutoGeneratedColumns)  
{  
    column.CurrentFilterFunction = Telerik.Web.UI.GridKnownFunction.NoFilter;  
    column.CurrentFilterValue = String.Empty;  
}  
 
grdUserSearchResults.Rebind();  
 

That method solved my problem.  Again, it appears so because my grid is using automatically generated columns.

Eric Skaggs
0
Golem
Top achievements
Rank 1
answered on 17 Jan 2012, 11:08 PM
I just thought I'd give a "shout out" to Eric's suggestion of using the "AutoGeneratedColumns" property.  I had the same situation, and this works perfectly.  I was originally just using the "Columns" property, which doesn't work for auto-generated columns.  Thanks.
Tags
Grid
Asked by
golddog
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Eric Skaggs
Top achievements
Rank 2
Golem
Top achievements
Rank 1
Share this question
or