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

How to clear all filters by javascript?

3 Answers 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
chi phi ngoc
Top achievements
Rank 1
chi phi ngoc asked on 10 May 2010, 04:52 AM
I have a table with structure:
[col1][col2][col3][col4]

By Javascript, I use:
...filter("col1_name", "abc1", "EqualTo");   [ok]

after I recall:
...filter("col1_name", "", "NoFilter");  [fail]
...filter("col2_name", "abc2", "EqualTo");  [ok]

But the result: the filter of col1 still not change.
How to clear all filters by Javascript?
Thanks,

3 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 10 May 2010, 10:28 PM
Have you looked over this forum thread? I believe the best thing for you to do here is actually clear the FilterExpressions collection that can be found within the client-side API of the RadGrid. I think the suggestions (along with the final post with the attached project) in that forum thread should help you out quite a bit!
0
chi phi ngoc
Top achievements
Rank 1
answered on 11 May 2010, 12:08 PM
Hi, this is my code:
var masterTable = $find("<%= KeywordRadGrid.ClientID %>").get_masterTableView();
alert(masterTable); //display Object [ok]
alert(masterTable.get_filterExpressions()); //display Empty


masterTable.get_filterExpressions().clear();// Not success, the filter is not clear when request

Somebody help me slove problem :(
0
Schlurk
Top achievements
Rank 2
answered on 11 May 2010, 03:16 PM
I did some experimenting and it would seem as if calling the filter function one after another might be your issue here. I actually set up two separate functions - one to create a filter and one to clear it:

        function columnClick(sender, args) { 
            var myGrid = $telerik.findGrid("RadGrid1"); 
            var myGridMasterTableView = myGrid.get_masterTableView(); 
            myGridMasterTableView.filter("CustomerID""A""StartsWith"); 
        } 
 
        function rowClick(sender, args) { 
            var myGrid = $telerik.findGrid("RadGrid1"); 
            var myGridMasterTableView = myGrid.get_masterTableView(); 
            myGridMasterTableView.filter("CustomerID""""NoFilter"); 
        } 

I subscribed to OnColumnDblClick and OnRowDblClick in the ClientEvents and tried these functions out. The interesting thing with your code is that you claim that filter("col1_name", "", "NoFilter") fails while the second filter function actually executes. For me it was the other way around - only the first filter() function actually worked while any subsequent call to that function was not represented in the RadGrid.

I believe the RadGrid has to rebind itself in order to execute that filter command and calling the filter command via javascript back-to-back might not be the way to do things. Have you looked into just clearing the filter in your function?
Tags
Grid
Asked by
chi phi ngoc
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
chi phi ngoc
Top achievements
Rank 1
Share this question
or