Kendo UI网格数据源在过滤器上触发额外的ajax请求

时间:2015-12-09 09:20:40

标签: javascript ajax kendo-ui kendo-grid kendo-datasource

我在我的项目中使用Kendo UI网格来构建订单列表,它有一个数据源,可以使用ajax请求立即加载所有订单,并在本地处理它们(过滤,排序,分页)没有其他要求。

这是我用来设置它的代码:

$("#layby-list").kendoGrid({
    columns: [
        {
            title: "Order date",
            field: 'order_d',
            filterable: {cell: {operator: "eq", showOperators: false}},
            format: "{0:dd/MM/yyyy}"
        },
        {
            title: "Order number",
            field: 'order_n',
            filterable: {cell: {operator: "eq", showOperators: false}},
        },
        {
            title: "Customer",
            field: 'customer',
            filterable: {cell: {operator: "startswith", showOperators: false}}
        }
    ],
    filterable: {
        mode: "row"
    },
    selectable: "row",
    sortable: true,
    resizable: true,
    navigatable: true,
    pageable: {
        pageSize: 10
    },
    groupable: true,
    dataSource: {
        transport: {
            read: {
                url: baseUrl,
                dataType: "json",
                type: "POST",
                data: {
                    action: 'loadOrders'
                }
            }
        },
        schema: {
            data: "data",
            total: "total",
            type: "json",
            model: {
                fields: {
                    order_d: {type: 'date'},
                    order_n: {type: 'number'},
                    customer: {type: 'string'}
                }
            }
        }
    }
});

这非常好,除非我尝试过滤"客户"列,因为该过滤器是自动完成,它执行完全相同的请求以加载网格以显示所有选项,因此问题是:是否可以通过在网格及其过滤器之间共享数据来避免该请求?

2 个答案:

答案 0 :(得分:1)

您可以将dataSource(http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.filterable.cell.dataSource)提供给“客户”列过滤器:

{
    title: "Customer",
    field: 'customer',
    filterable: {
        cell: {
            operator: "startswith",
            showOperators: false,
            dataSource: new kendo.data.DataSource({
                data: [
                    { customer: "...." },
                    { customer: "...." },
                    { customer: "...." }
                ]
            }),
        }
    }
}

答案 1 :(得分:1)

我遇到了同样的问题并解决了改变

的问题
filterable: {
    mode: "row"
},

filterable: {
    mode: "menu"
},