The extension method that KendoUI adds (ToDataSourceResult), seems to fail on Pages > Page #1. It works fine the first time the page loads, but then when I try to use it with virtual scrolling, to fetch pages, 2,3,4 ... N asynchronously, the method ignores all the data in the IEnumerable object I am trying to transform.
My code is as follows:
I have a MVC controller that fetches data like so:
Database database = Database.GenerateDatabase();
ResultSet queryResults = database.GetEvents(
FilterHelper.GenerateQueryCriteria((List<IFilterDescriptor>) request.Filters, request.Page, request.PageSize)
);
Database.GetEvents returns an object like so:
public class ResultSet {
public List<ResultSetRow> Set;
public int PageRowCount;
public int TotalRecordCount;
}
Each ResultSetRow, is an instance of a class that has 1 string, and 2 ints as properties.
At this point, I set a break point and inspect the contents of ResultSet.Set. The database is properly populating the List with as many records as I specified with request.PageSize. I have confirmed that results are being returned for any and all page numbers.
The next stage, everything goes badly:
DataSourceResult result = ((IEnumerable<ResultSetRow>) queryResults.Set).ToDataSourceResult(request);
I inspect the contents of the DataSourceResult object, and its array property 'Data' is empty.
Why is my model (ResultSetRow), failing to convert to Kendo's DataSourceResult object?
Some additional info:
Thanks for your help SO community
The main reason for using ToDataSourceResult()
is that it runs filtering / ordering / grouping / paging on the database server. As such, it works best when given an IQueryable
that hasn't yet been executed.
It does work on an IEnumerable
, but then you have to load the entire table into memory, which is not scalable.
Because you only get one page's worth of data, when ToDataSourceResult
is called, it thinks that is all the data in the database, and so returns an empty list for pages other than the first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With