Demonstrates a Telerik Grid in Blazor, using the OnRead event along with Dapper and Dapper.SqlBuilder, to generate your SQL queries on the fly supporting most aspects of Telerik Grid.
Telerik Grid works nicely with Entity Framework, you can use .ToDataSourceResultAsync()
and everything for sorting etc happens on the database. If you are using Dapper you can use that, however as Dapper doesn't return an IQueryable, you will be fetching the entire dataset and then filtering, paging and sorting in code, rather than on your database.
Special thanks to @pingu2k4 for the sample.
- Paging
- Sorting
- Filtering
- Grouping
- Aggregate Information
-
Open the project, right click on the
TelerikBlazorGrid.SqlDB.sqlproj
file and thenImport
->Script(*.sql)
-
Click Next on the window that popped
-
After that, choose Multiple files and click Browse...
-
Select the Scripts folder in the project and click Finish
-
Right click again on the
TelerikBlazorGrid.SqlDB.sqlproj
file and thenPublish...
-
Click Edit in the popped window
-
Type Server Name and User Name from your SQL Server
-
Copy the generated connection string and close the window
-
Paste the connection string in the
appsettings.Development.json
file and you are ready to go
If you are looking for where the majority of the code that performs this is held, take a look at TelerikBlazorGrid_Dapper.DataAccess.Extensions.SqlBuilderExtensions
. We build up 2 sql templates, one for the query to get our data, and another to query the total count.
By default, you should only need to provide this method the table (or view) name you wish to query. However there are instances where you wish to query a different table or view for both the data selection and the count - For example where you have a view containing a join as the count will become inaccurate, counting all the duplicate rows.
You may also specify a different default sort field and direction.
This picture shows the end result. A table with full sort, filter and paging functionality - Using OnRead through dapper, and passing the handling of all the Grid functionalities over to the database.
Integration with Dapper is not subject to technical support by Progress.