Problem:
While
working with MVC Telerik GridView let’s say you have some default filters using
Filterable,
as mentioned in below code:
@(Html.Telerik().Grid(Model)
.Name("testGrid")
.Columns(c
=>
{
c.Bound(m => m.Id).Width(30);
c.Bound(m => m.Name).Width(110);
c.Bound(m => m.Telephone).Width(100);
c.Bound(m => m.IsActive).Width(100);
})
.DataBinding(dataBinding =>
{
dataBinding.Ajax().Select("<Action-Name>", "<Controller-Name>",
new { id
= Guid.NewGuid().ToString()
});
})
.Sortable()
.Pageable(paging => paging.PageSize(100))
.Filterable(filtering => filtering
.ShowOrOption(true)
.Filters(filters => filters.Add(T => T.IsActive).IsEqualTo("Yes")))
.Selectable()
)
|
And suppose
there is one search button, on click of that you are refreshing the grid with
the help of rebind method, as mentioned in below code:
$("#searchButton").click(function () {
$('#testGrid').find("tr.t-no-data td").html("Please
wait...");
$('#testGrid').data('tGrid').rebind({ empId: '' });
$('#testGrid').find("tr.t-no-data td").html("No records");
});
|
After
refresh you’ll see that default filter IsActive of GridView is no more
there.
Reason
and Solution:
Default
filter are removed on GridView rebind method because this method reset the
filters, and if you try to see “filter by” property in jQuery debugging then it’ll
be blank after grid rebind happens.
To solve
this problem we can use ajaxRequest method to refresh the
grid instead of rebind method, see the updated and working code below:
$("#searchButton").click(function () {
$('#testGrid').find("tr.t-no-data td").html("Please
wait...");
//Use ajaxRequest instead of rebind so that filter won't
reset.
$('#testGrid').data('tGrid').ajaxRequest({empId:
'' });
$('#testGrid').find("tr.t-no-data td").html("No
records");
});
|
Comments
Post a Comment