使用OR运算符过滤单个列

时间:2017-08-23 09:09:12

标签: kendo-ui kendo-grid kendo-asp.net-mvc

想要在同一列中的kendo网格中进行过滤,以获得来自多选字段的值的并集:

$('#btnSearchRoles').click(function (e) {
        e.preventDefault();

        //process searched roles
        var multiselect = $("#RoleSubroleId").data("kendoMultiSelect");
        // get data items for the selected options.
        var dataItem = multiselect.dataItems();
        var filterCode = "[";
        for (var i = 0; i < dataItem.length; i++) {
            filterCode += "{ field: 'RolesAsString', operator: 'contains', value: '" + dataItem[i].Name + "'},"
        }
        filterCode += "]";

        //start filtering
        var dataSource = $("#grid").data('kendoGrid').dataSource;
        dataSource.filter({
            logic: "or",
            filters: filterCode
        });
    });

即使filterCode被正确填充,过滤器也无法到达DataSourceRequest request参数。 enter image description here

1 个答案:

答案 0 :(得分:0)

我使用JS方法的push方法来替换过滤器的字符串组成:

$('#btnSearchRoles').click(function (e) {
        e.preventDefault();

        //process searched roles
        var multiselect = $("#RoleSubroleId").data("kendoMultiSelect");
        // get data items for the selected options.
        var dataItem = multiselect.dataItems();
        var setFilter = { logic: "or", filters: [] };
        for (var i = 0; i < dataItem.length; i++) {
            setFilter.filters.push({ field: "RolesAsString", operator: "contains", value: dataItem[i].Name });
        }

        //start filtering
        var dataSource = $("#grid").data('kendoGrid').dataSource;        
        dataSource.filter(setFilter);
    });