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

[Solved] How to know on client side if filters applied to RadGrid

2 Answers 364 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tushar
Top achievements
Rank 1
Tushar asked on 19 Jun 2014, 08:55 AM
Hi,
I want to disable my custom "Clear Filter" header menu if there are no filters applied to the RadGrid.
But I am not able to know if filters are applied.

I have tried solutions mentioned in below link
http://stackoverflow.com/questions/8188990/how-to-know-when-filters-are-used-when-using-telerik-rad-grid
including 
sender.get_masterTableView().get_filterExpressions()
sender.get_masterTableView().get_filterExpressions().toOql()

But I am not able to get the filterExpressions successfully.

Can anyone please provide correct code?

2 Answers, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 23 Jun 2014, 01:58 PM
Hello Tushar,

You could use the following approach for determining whether or not the grid have applied filters by traversing through each column and retrieving the current filter function. If any of the filter functions differs from "NoFilter", then there is filter applied:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function clickHandler(sender, args) {
            var grid = $find("<%=RadGrid1.ClientID%>");
            var isFilterApplied = isFilterAppliedToGrid(grid);
            console.log(isFilterApplied);
        }
 
        function isFilterAppliedToGrid(grid) {
            var columns = grid.get_masterTableView().get_columns();
 
            for (var i = 0; i < columns.length; i++) {
                if (columns[i].get_filterFunction() != "NoFilter") {
                    return true;
                }
            }
 
            return false;
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadButton runat="server" ID="RadButton1" AutoPostBack="false" OnClientClicked="clickHandler"></telerik:RadButton>
 
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="true" OnNeedDataSource="RadGrid1_NeedDataSource">
</telerik:RadGrid>

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Tushar
Top achievements
Rank 1
answered on 07 Jul 2014, 10:21 AM
Thanks Konstantin!!
Tags
Grid
Asked by
Tushar
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Tushar
Top achievements
Rank 1
Share this question
or