Kendo ui mesh filter, sorting and paging on the server

I am using kendo grid and want to do filtering, sorting and swapping on the server. I understand that I have to add to dataSource:

serverPaging: true, serverSorting: true 

But how can I specify grid / dataSource, which url should use for sorting, filtering, etc. And what if I want to do the sorting myself? I want to use control kendo, but go to the server myself. Is there an event like "sortTriggered" where I can call "prevntDefault" or something like that ... I don't know.

+6
source share
3 answers

Take a look at this sample. It uses the MobileServices java script for Windows Azure, but it shows you how to handle swap and server sorting yourself.

http://jsbin.com/efeKiwO/11/edit

In the transport function of your data source, each method (read, update, create, destroy) can be configured to function (this is a read function, it handles any sorting and swapping).

 read: function(options) { // Get the table var table = client.getTable("Customer"); // Build base query var query = table.includeTotalCount(); // Add paging if(options.data.skip !== undefined && options.data.take !== undefined) { query = query.skip(options.data.skip).take(options.data.take); } // Add sorting if(typeof options.data.sort !== "undefined" && options.data.sort !== null) { for(var i = 0; i< options.data.sort.length; i++) { if(options.data.sort[i].dir === "desc") { query = query.orderByDescending(options.data.sort[i].field); } else { query = query.orderBy(options.data.sort[i].field); } } } var promise = query.read(); promise.done(function(data) { options.success(data); }); }, 

Inside this function, you can do whatever you want. Instead of using a javascript library such as this sample, you can make a call to $ .getJSON or a call to $ .ajax or something else that you want to do. The function parameter object will contain everything you need for swapping, sorting and filtering. When you have data, just call options.success (dataSet); with your properly sorted / paged DataSet, and your grid will be bound to it.

+3
source

Your configuration is practically absent,

Not enough secret sauce to connect to MVC.

Suppose your DataSource configuration is as follows:

 var myDataSource = new kendo.data.DataSource({ transport: { read: { url: 'Users/Read', type: 'POST' } }, serverSorting: true, serverFiltering: true, serverPaging: true } 

On your server side in UserController.cs (example) you should get [DataSourceRequest]

 public DataSourceResult Read([DataSourceRequest] DataSourceRequest request) { // Here you might actually get the items from your cache or database. var List<User> myList = new List<User>(); // Here is when the kendo magic happens. return myList.ToDataSourceResult(request); } 

Why is [DataSourceRequest] important?

Since it contains the parameters of the search call, sorting, filtering, which your grid requests on the server. Therefore, if you want to execute the algorithm yourself, you must examine the request and process these spurious elements. Remember to return an instance of the DataSourceResult object.

If your objects live in a cache, and your fields do not need special processing for filtering, grouping, sorting, etc., just use the Cendo C # ToDataSourceResult extension. It will process your elements and apply filtering, sorting, tuning of the search call using dynamic LINQ operators.

+3
source

The Kendo grid uses only one URL to retrieve data, and it will be taken from the DataSource.

This URL will be called by the grid every time it needs data, and the sort and swap parameters will be added to every request made by the server database in the context of the grid.

Then the server will receive a standard web request with all the parameters necessary to create your own request. Then you will need to send the response as properly formatted (ex: JSONP OData).

0
source

All Articles