Last Updated:
25 Mar 2024 13:37
by ADMIN
Kendo Grid server filtering json impact (Not just MVC but any version of the grid)
Server filtering kendo grids and json deserialization errors in asp.net.
When we are managing large volumes of data with several thousand datasource objects (grid rows) all of the rows need to be transported with each event.
This leads to errors with the json being too large to serialize.
We wish to restrict the data footprint and only return data for the page requested.
so if the grid has 100 pages and page size is 10 we only want to return the 10 rows required for the page, not 1000 rows.
This is not possible with the Kendo grid.
To work around this issue we have devised a strategy to return the the number of datasource objects Kendo grid expects up to the requested page count, but they are empty objects with no data, and then only have the last 10 rows populated with data.
It would be better for the grid control just to expect the number of results expected to the selected page and not have to add the dummy rows, so long as the total number of rows is provided so that the grid knows how many pages there are.
Our work around looks something like this in asp.net MVC
var users = cm.getUsers();
var result = new DataSourceResult();
var results = new List<user>();
int index = 0;
if (pageNum == 1)
results = users.Take(pageSize).ToList();
else
{
index = pageSize * (pageNum - 1);
results = users.Skip(index).Take(pageSize).ToList();
}
List<user> output = null;
[This is the bit that should be handled by the kendo grid, without the need for dummy rows to further reduce json size]
if (index == 0)
{
output = new List<user>(results);
}
else
{
output = new user[index].ToList();
output.AddRange(results);
}
result = output.ToDataSourceResult(request);
result.Total = users.Count();
return Json(result, JsonRequestBehavior.AllowGet);