Kendo DataSource Filtering with multiple conditions

datasourcekendo-ui

I want to build a filter for a datasource with multiple condition. I found this thread (HERE) where the guys have almost the same problem, but me I want to make a OR and not a AND between my two operation.

There is the code I have so far :

        var filter = { logic: "OR", filters: [] };

        var filterProduct = { logic: "AND", filters: [] };
        var supplierValue = dropdownSupplier.value();
        if (supplierValue != "00000000-0000-0000-0000-000000000000") {
            filterProduct.filters.push({ field: "SupplierId", operator: "eq", value: supplierValue });
        }

        var categoryValue = dropdownCategory.value();
        if (categoryValue != "00000000-0000-0000-0000-000000000000") {
            filterProduct.filters.push({ field: "CategoryId", operator: "eq", value: categoryValue });
        }

        var typeValue = dropdownType.value();
        if (typeValue != "00000000-0000-0000-0000-000000000000") {
            filterProduct.filters.push({ field: "TypeId", operator: "eq", value: typeValue });
        }


        var filterSelect = { logic: "OR", filters: [] };
        filterSelect.filters.push({ field: "Id", operator: "eq", value: "00000000-0000-0000-0000-000000000000" });

        filter.filters.push(filterProduct);
        filter.filters.push(filterSelect);

        dropdownProduct.dataSource.query({ filter: filter });

In fact what I want to do it's to have : (filterProduct) OR (filterSelect) but if i'm not using "logic" in the variable filter, the filter will be an "AND".

Thanks alot

edit: There is a jsFiddle close to what I want to do but with the "AND" : Example In this example the filter is :
[ {[ Freight = 11.61 OR Freight = 51.30 ]} AND {[ City startswith "Charleroi" ]} ]

But I want to have somethign like :
[ {[ Freight = 11.61 OR Freight = 51.30 ]} OR {[ City startswith "Charleroi" ]} ]

Best Answer

There is the final code working properly :

The keyword AND and OR need to be lowercase and I don't need to use the variable filterSelect

    var filter = { logic: "or", filters: [] };
    var filterProduct = { logic: "and", filters: [] };
    var supplierValue = dropdownSupplier.value();
    if (supplierValue != "00000000-0000-0000-0000-000000000000") {
        filterProduct.filters.push({ field: "SupplierId", operator: "eq", value: supplierValue });
    }
    var categoryValue = dropdownCategory.value();
    if (categoryValue != "00000000-0000-0000-0000-000000000000") {
        filterProduct.filters.push({ field: "CategoryId", operator: "eq", value: categoryValue });
    }
    var typeValue = dropdownType.value();
    if (typeValue != "00000000-0000-0000-0000-000000000000") {
        filterProduct.filters.push({ field: "TypeId", operator: "eq", value: typeValue });
    }
    if (filterProduct.filters.length > 0) {
        filter.filters.push(filterProduct);
    }
    filter.filters.push({ field: "Id", operator: "eq", value: "00000000-0000-0000-0000-000000000000" });
    dropdownProduct.dataSource.query({ filter: filter });
Related Topic