kendo ui 网格过滤,服务器中的排序和分页 [英] kendo ui grid filter, sort and paging in the server

查看:37
本文介绍了kendo ui 网格过滤,服务器中的排序和分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用剑道网格并希望在服务器中执行过滤、排序和分页.我知道我应该添加到数据源:

I'm using kendo grid and want to perform filtering, sorting and paging in the server. I understand that I should add to the dataSource:

serverPaging: true,
serverSorting: true

但是我如何告诉网格/数据源它应该使用哪个 url 来进行排序、过滤等.如果我想自己执行 sortig 怎么办?我想使用剑道提供的控制,但我自己去服务器.有没有像sortTriggered"这样的事件,我可以在其中调用prevntDefault"或类似的东西......我不知道.

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

推荐答案

看看这个示例.它使用适用于 Windows Azure 的 MobileServices javascript api,但向您展示了如何自行处理服务器分页和排序.

Take a look at this sample. It is using the MobileServices javascript api for Windows Azure, but shows you how to handle server paging and sorting on your own.

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

在数据源的传输函数上,每个方法(读取、更新、创建、销毁)都可以配置为一个函数(这是读取函数,它处理任何排序和分页).

On the transport function of your dataSource, each method (read,update,create,destroy) can be configured to a function (this is the read function, it handles any sorting and paging).

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);
        });
      },

在该函数中,您可以做任何您喜欢的事情.您可以进行 $.getJSON 调用、$.ajax 调用或其他任何您想做的事情,而不是使用像本示例这样的 javascript 库.该函数的参数对象将包含分页、排序和过滤所需的一切.获得数据后,只需调用 options.success(dataSet);使用您正确排序/分页的数据集,您的网格将绑定到它.

Inside that function you can do whatever you like. Instead of using a javascript library like this sample, you could make a $.getJSON call, or a $.ajax call, or whatever else you want to do. The parameter object to the function will contain everything you need for paging, sorting, and filtering. Once you have the data, just call options.success(dataSet); with your properly sorting/paged dataSet and your grid will bind to it.

这篇关于kendo ui 网格过滤,服务器中的排序和分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆