简体   繁体   中英

kendo ui datasource filter “in”

How can i filter kendo datasource with operator "in"? Example:

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) }
    });
}

The DataSource filter option doesn't support this, so you'll have to filter the data before creating the data source, eg like this:

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM