Telerik c# MVC Grid customizing Paging with Custom sql query + Dapper

Telerik Mvc Web framework has an option to customize the paging of the grid.In most of the cases we are leaned towards to use its default option of paging/filtering.But It actually take all the data and filter or page or sort on top the all content from the back end ,this is the performance breach .

Here I am trying to describe the ways we can customize the Telerik   Mvc Paging without taking the bulk data.

There are 3 steps to do.
1.Make the telerik grid settings for the customization
2.Get the total count of data in the initial request.
3.Apply custom filter queries to filter from the back end.

1.Make the Telerik grid settings for the customization


Here is  a sample code to set up the grid with custom paging :


Here please note the Total we set after the ajax option.This value we need to get from the controller using Viewbag or any other data transfer methods to let the grid know the total.
.EnableCustomBinding true.

Set the data read option

In controller Read action,We will get the datasource object from there,we can extract the page number size filter etc.So according to these values we can extract /filter data from Db.

Sample code for Controller Read :



Make the Filter logic from the request and you can pass the page number and page size to filter from the data. Return the data source request with the total,and filtered data.Make sure the total amount to set in the data source object which returns back.

Sample Dapper query I used to get the desired amount of data :


Sample working example is given below:




That's all.Please comment If you have any query.

Happy Programming!!

#Telerik #Microsoft #Mvc #Dapper


Comments

Post a Comment

Popular posts from this blog

Configure Facebook Webhook[WebSub protocol]

SendGrid Integration with c#