kendo网格服务器重新过滤数据源

时间:2015-08-20 14:29:33

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

$(document).ready(function () {

    var agenciesData = new kendo.DataToken.DataSource({
        type: 'webapi',
        transport: {
            read: { url: "/api/Agencies/", dataType: "json", data: { activity: getActivity() } },
            create: { url: "/api/Agencies", type: "POST", dataType: "json" },
            destroy: { url: "/api/Agencies/{0}", type: "DELETE" },
            update: { url: "/api/Agencies/{0}", type: "PUT" },
            idField: "ID"
        },
        filter: [{ field: "Activity", operator: "eq", value: getActivity() }],
        pageSize: 15,
        page: 1,
        total: 0,
        serverPaging: true,
        serverSorting: true,
        serverFiltering: true,
        schema: {
            data: "Data",
            total: "Total",
            model: {
                id: "ID",
                fields: {
                    ID: { editable: false, type: "number" },
                    AgencyName: { type: "string" },
                    AgentName: { type: "string" },
                    Address: { type: "string" },
                    City: { type: "string" },
                    Tel1: { type: "string" },
                    Tel2: { type: "string" },
                    Pele: { type: "string" },
                    Activity: { type: "number" },
                    ToDate: { type: "date" }
                }
            }
        }
    });

    $("#agenciesGrid").kendoGrid({
        dataSource: agenciesData,
        toolbar: [{ text: "valid", className: "validAgents" }, { text: "not valid", className: "notValid" }, { text: "all", className: "allAgents" }, { text: "potential", className: "potetial" }],
        editable: false,
        navigatable: true,
        sortable: true,
        autoBind: false,
        height: 430,
        pageable: { refresh: true },
        columns: [
            { field: "ID", hidden: true },
            { field: "AgencyName", title: "agency", width: 150, filterable: { cell: { operator: "contains" } } },
            { field: "AgentName", title: "agent", width: 150, filterable: { cell: { operator: "contains" } } },
            { field: "Address", title: "address", width: 200, template: "#= Address + ' ' + City #", filterable: false },
            { field: "Tel1", title: "phones", width: 300, template: "#= Tel1 + ' : ' + Tel2 + ' : ' + Pele #", filterable: false },
            { field: "Activity", title: "active", width: "90px" },
            { field: "ToDate", title: "end Contract", type: "date", width: 90, format: "{0:dd/MM/yyyy}", parseFormats: ["yyyy-MM-ddThh:mm:ss"] }
        ]
    });


    $(".validAgents").click(function () { //valid
        $("#myActivity").val("1");
        $('#agenciesGrid').data().kendoGrid.dataSource.read({ activity: "1" });
    });

    $(".notValid").click(function () {//notValid
        $("#myActivity").val("2");
        $('#agenciesGrid').data().kendoGrid.dataSource.read({ activity: "2" });
    });

    $(".potetial").click(function () {//potetial
        $("#myActivity").val("3");
        $('#agenciesGrid').data().kendoGrid.dataSource.read({ activity: "3" });
    });
});


function getActivity(){
    var myActivity = $("#myActivity").val();
    return myActivity;
}

当我使用已经按参数过滤的kendo网格时:$('#someGrid')。data()。kendoGrid.dataSource.read({activity:value}); 我看到了获取: https://localhost:44305/api/Agencies/?sort=&page=1&pageSize=15&group=&filter=&activity=1

网格按预期过滤,但是,当我想进行分页,排序,刷新时 - 我得到的整个数据忽略了我所做的过滤器。 我看到了获取: https://localhost:44305/api/Agencies/?sort=&page=1&pageSize=15&group=&filter=

如何保存我的过滤器状态以对来自服务器端的数据进行分页和排序? 即使我使用差异方法,如"可滚动:{virtual:true}"当我向下滚动时 - 每个请求都没有过滤......

由于

1 个答案:

答案 0 :(得分:1)

你试过吗

var agenciesData = new kendo.DataToken.DataSource({
  filter : function () {
     return object;
  }
});

我的意思是尝试使用filter作为函数,您可以根据具体情况在函数内部执行逻辑。