Kendo网格:如何从一列远程过滤2个值以上

时间:2015-01-22 12:58:05

标签: javascript kendo-ui kendo-grid filtering

我在kendo网格中有一列,但如果我在服务器API的对面过滤,我需要过滤两个值。

这意味着:

{
    "entityName": "client",
    "data": {
        "take": 10,
        "skip": 0,
        "page": 1,
        "pageSize": 10,
        "filter": {
            "logic": "and",
            // IN FILTER IS IMPORTANT TO HAVE 2 OBJECTS    
            "filters": [
                {
                    "operator": "eq",
                    "value": "test",
                    "field": "client.name"
                },
                {
                    "operator": "eq",
                    "value": "test",
                    "field": "client.surname"
                }
            ]
        },
        "group": []
    }
}

我通过这种方式尝试过:

filterable : {
                    cell :
                        [
                            {

                                dataTextField : "client.name",
                                operator : "contains"
                            },
                            {

                                dataTextField : "client.surname",
                                operator : "contains"
                            }
                        ]
                }

但没有运气。

我该怎么办?

非常感谢您的任何建议。

1 个答案:

答案 0 :(得分:0)

为了做到这一点,您必须截取dataSource数据请求并在readOptions到达服务器之前更改其中的过滤器。您必须创建自定义transport.read,每次dataSource请求某些数据时,它都会将readOptions参数传递给该函数。

myGrid.kendoGrid({
  dataSource: {
    serverFiltering: true,
    transport: {
      read: function (readOptions) {
        readOptions.filter.filters = [{
            operator: "eq",
            value: "test",
            field: "client.name"
          }, {
            operator: "eq",
            value: "test",
            field: "client.surname"
          }];

        //Insert you logic to retrieve the data from the server
        //You may also try to call the dataSource original read function and pass the modified readOptions
        //The ajax is just an example...
        $.ajax({data: readOptions}).done(function(data){
          readOptions.success(data);
        });


      }
    }
}

请记住,如果覆盖read函数,则需要调用readOptions成功/错误函数来通知dataSource有关数据回调的信息。