I have a Telerik Blazor Grid that I want to be able to use built in column filtering, column sort and paging.
There is a large amount of data to be displayed in the grid approx. 200,000+ rows hence the need for paging.
Ideally I want to do all the filtering, sorting and paging within the SQL query so that the SQL server will do the heavy lifting and only send back the required single page of data based on the applied filters, sorting and page number.
I have the Telerik.DataSource.DataSourceRequest object from the grid that contains all the grid state for currently applied filters, sorting and page number, is there a way I can use this object to generate my SQL query e.g. create the WHERE clause based on the filters and the ORDER BY clause based on the sorting and the page of data based on the page number?
I am using ServiceStack OrmLite which is returning an IQueryable from the SQL database then I'm using the extension method .ToDataSourceResultAsync(gridRequest);
I seems that the grid state in the gridRequest is happening in memory on the data sent back from the SQL query in the IQueryable object and not on the SQL database.
Is there a way I can do the filtering etc on the SQL database within the query rather than in memory?
Example:
DataSourceResult processedData = null;
using (var db = _dbConnectionFactory.Open())
{
Telerik.DataSource.DataSourceRequest gridRequest = dataSourceRequestWrapper.ToDataSourceRequest();
var q = db.From<PersonTable>().Limit(0, 100);
processedData = await db.Select(q).AsQueryable().ToDataSourceResultAsync(gridRequest);
db.Close();
}
return processedData;
This produces a SQL query like:
SELECT
TOP 100
"PersonId",
"FirstName",
"Surname",
"Age"
FROM
"dbo"."PersonTable"
Ideally with using the extension method .ToDataSourceResultAsync(gridRequest); I would like to see the SQL query look more like based on the grid being sorted by the Age column descending and a single text filter applied to the Surname column to filter on 'Smith':
SELECT
TOP 100
"PersonId",
"FirstName",
"Surname",
"Age"
FROM
"dbo"."PersonTable"
WHERE
"Surname" LIKE 'Smith%'
ORDER BY
"Age" DESC