Reputation: 4412
I have some Kendo Grid's and Scheduler's and I want to apply a complex filter like ((A or B or C) and (D or E)). If the filter is simple, like (A or B or C), everything ok, but with the first mentioned complex type of filter, I'm not able to achieve it.
Here's what I have tried:
function filterByTechnicalAndStatus() {
var allFilters = [];
var technicalFilters = { logic: "or", filters: [] };
var statusFilters = { logic: "or", filters: [] };
var scheduler = $("#scheduler").data("kendoScheduler");
var userGrid = $("#userGrid").data("kendoGrid");
var selectedUsers = userGrid.select();
if (selectedUsers.length != 0) {
for (var i = 0; i < selectedUsers.length; i++) {
var code = userGrid.dataItem(selectedUsers[i]).Code;
technicalFilters.filters.push({ field: "Technical", operator: "eq", value: code });
}
}
if ($('#chk_PL').prop('checked')) {
statusFilters.filters.push({ field: "InspectionStatusCode", operator: "eq", value: "PL" });
}
if ($('#chk_OPEN').prop('checked')) {
statusFilters.filters.push({ field: "InspectionStatusCode", operator: "eq", value: "OPEN" });
}
if ($('#chk_EXEC').prop('checked');) {
statusFilters.filters.push({ field: "InspectionStatusCode", operator: "eq", value: "EXEC" });
}
allFilters.push(statusFilters);
allFilters.push(technicalFilters);
scheduler.dataSource.filter(
[
{ "logic": "or",
"filters": [
{ "field": "InspectionStatusCode", "operator": "eq", "value": "PL" },
{ "field": "InspectionStatusCode", "operator": "eq", "value": "OPEN" }
]
},
{ "logic": "or",
"filters": [
{ "field": "Technical", "operator": "eq", "value": "PSOARES" },
{ "field": "Technical", "operator": "eq", "value": "ASOARES" }
]
}
]
);
//scheduler.dataSource.filter(allFilters);
}
At the end of the above function, I've got scheduler.dataSource.filter
set "manually" and just below a commented line. The manual setting works as expected: however, I don't want to do that "manually", obviously.
The commented line is what I expected to work fine but breaks and opens the kendo.all.min.js
file with a syntax error alert.
I have found this and this but wasn't able to overcome my problem. How can I set a complex filter other than "manually"?
Upvotes: 1
Views: 1579
Reputation: 40887
Try doing:
ds.filter([
{
"logic":"and",
"filters":[
{
"logic":"or",
"filters":[
// Your A condition
{ "field": "InspectionStatusCode", "operator": "eq", "value": "PL" },
// Your B condition
{ "field": "InspectionStatusCode", "operator": "eq", "value": "OPEN" }
{
// Your C condition
}
]
},
{
"logic":"or",
"filters":[
{
// Your D condition
},
{
// Your E condition
}
]
}
]
}
]);
I.e. Write a first filter with login "AND" which contains two filters. Each of these filters have and "OR" filter with the conditions that you want.
Remember that:
Upvotes: 4