Reputation: 2611
I have multiple filters that I am going to apply on the kendo grid datasource.
If I have a filter like below, everything is okay where gridConfig is the configuration of my kendo grid:
var mainFilters = [];
mainFilters.push({
field: "x",
operator: "eq",
value: 1
});
mainFilters.push({
field: "y",
operator: "eq",
value: 2
});
gridConfig.instance.dataSource.filter({
logic: "and",
filters: mainFilters
});
My problem is in here. I have another property lets say z that is an array of values. I want to filter the kendo grid datasource on z propery values with OR logic. For example, here is my z propery filter:
zFilters.push(
{ field: "z", operator: "eq", value: 3},
{ field: "z", operator: "eq", value: 4});
gridConfig.instance.dataSource.filter({
logic: "or",
filters: zFilters
});
Now, I want to combine these two filters and apply them simultaneously on my kendo grid datasource. It means that my final result is based on this logic:
(x = 1) AND (y = 2) AND (z = 3 OR z = 4)
How can I do this with kendo filters?
Upvotes: 5
Views: 4727
Reputation: 3711
All sub-filters have to be in an array! This will work:
grid.dataSource.filter(
{
logic: "and",
filters: [
{
filters:[{ field: "x", operator: "eq", value: 1 }]
},
{
filters:[{ field: "y", operator: "eq", value: 2 }]
},
{
logic: "or",
filters:[
{ field: "z", operator: "eq", value: 3},
{ field: "z", operator: "eq", value: 4}
]
}
]
}
);
Upvotes: 4
Reputation:
The structure it has to be in to be applied to a widget if you have mixed 'or' and 'and' filters is
{
logic: "and",
filters: [
{ field: "x", operator: "eq", value: 1},
{ field: "y", operator: "eq", value: 2},
{ logic: "or", filters: [{ field: "z", operator: "eq",value: 3 }, { field: "z", operator: "eq",value: 4 }]}
]
}
finally
grid.dataSource.filter(abovefilterobject)
hope it helps
Upvotes: 1