I have a fairly conventional grid with multiple filtered columns. Is it or isn't it possible to clear all filters at once in JavaScript?
I've looked at multiple examples in this forum but I haven't been able to get anything to work correctly so far. I don't see any clear definitive answers.
I've looked at multiple examples in this forum but I haven't been able to get anything to work correctly so far. I don't see any clear definitive answers.
4 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 20 Feb 2013, 10:55 AM
Hi Boris
I tried an approach to clear filters on button click.
Try the following markup and JS and let me know your concern.
aspx:
JS:
Thanks
Shinu.
I tried an approach to clear filters on button click.
Try the following markup and JS and let me know your concern.
aspx:
<
asp:Button
ID
=
"Button1"
runat
=
"server"
OnClientClick
=
"btnclick()"
/>
<script type=
"text/javascript"
>
function
btnclick()
{
var
grid = $find(
'<%=RadGrid1.ClientID%>'
);
var
tableView = grid.get_masterTableView();
tableView.getColumnByUniqueName(
"FirstName"
).set_filterFunction(0);
tableView.get_filterExpressions().clear();
var
filterRow = $telerik.$(grid.get_element()).find(
".rgFilterRow"
);
//FirstName is the name of the column in my case; just substitute it with your own.
var
txtProductID = $telerik.findElement(filterRow[0],
"FirstName"
)
txtProductID.value =
""
;
tableView.rebind();
}
</script>
Thanks
Shinu.
0

Boris
Top achievements
Rank 1
answered on 20 Feb 2013, 04:01 PM
That's good for one filter, not all filters at once.
(If I understand correctly, any clearing of a single filter causes a postback?)
(If I understand correctly, any clearing of a single filter causes a postback?)
0
Hi Boris,
If you want only to clear the values from the controls into the filter item you do not need postback, you can get all columns by their UniqueName, by using getColumnByUniqueName, find the corresponding controls with findElement() or findControl() functions and clear their values. However if you want to remove the filter expressions from the RadGrid and return the data before filtering into the RadGrid you need to perform postback in order to get the new data for the RadGrid. For example the following code will clear all filter controls values and will return RadGrid in initial state with no filtered data into it:
I hope this helps.
All the best,
Radoslav
the Telerik team
If you want only to clear the values from the controls into the filter item you do not need postback, you can get all columns by their UniqueName, by using getColumnByUniqueName, find the corresponding controls with findElement() or findControl() functions and clear their values. However if you want to remove the filter expressions from the RadGrid and return the data before filtering into the RadGrid you need to perform postback in order to get the new data for the RadGrid. For example the following code will clear all filter controls values and will return RadGrid in initial state with no filtered data into it:
foreach
(var column
in
RadGrid1.MasterTableView.RenderColumns)
{
column.ResetCurrentFilterValue();
}
RadGrid1.MasterTableView.FilterExpression =
""
;
RadGrid1.Rebind();
I hope this helps.
All the best,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

Boris
Top achievements
Rank 1
answered on 22 Feb 2013, 12:49 PM
Actually my only motivation for trying to have a JavaScript clear command was so I could have an HTML input button identical in appearance to all the others that were setting individual Filters.
I gave up and included roughly the same C# code as what you've shown in the item command of the refresh button.
Probably better since it's more intuitive and simplified the screen.
Thanks.
I gave up and included roughly the same C# code as what you've shown in the item command of the refresh button.
Probably better since it's more intuitive and simplified the screen.
Thanks.