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

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

问题描述

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

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

但是我如何告诉grid/dataSource它应该用于排序,过滤等的URL. 如果我想自己执行排序,该怎么办?我想使用kendo提供的控件,但自己去服务器.是否有类似"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天全站免登陆