kendo ui数据源过滤器“in”

时间:2014-07-26 14:52:52

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

如何使用运算符"在"中过滤kendo数据源? 例如:

var original_data = [
    {"group": [1, 2], "name": "Coca Cola"},
    {"group": [1, 3], "name": "Pizza"}
];
function filter_articles(original_data, group) {
    return new kendo.data.DataSource({
        data: original_data,
        filter: { field: 'group', operator: 'in', value: parseInt(group) }
    });
}

1 个答案:

答案 0 :(得分:1)

DataSource过滤器选项不支持此功能,因此您必须在创建数据源之前过滤数据,例如:像这样:

var original_data = [{
    "group": [1, 2],
    "name": "Coca Cola"
}, {
    "group": [1, 3],
    "name": "Pizza"
}];

function filter_articles(original_data, group) {
    var filtered = original_data.filter(function (item) {
        return item.group.indexOf(group) !== -1;
    });

    var ds = new kendo.data.DataSource({
        data: filtered
    });
    ds.read();

    return ds;
}

var filteredDs = filter_articles(original_data, 3);

demo