basically right now grid using AND when filter column1 and column2 and column3, is it possible to change the filter logic to OR?
2 Answers, 1 is accepted
0
Accepted
Mihaela
Telerik team
answered on 20 Apr 2021, 10:19 AM
Hi Aleksandr,
Thank you for your inquiry.
Indeed, you could create your own filtering expression with the logic "OR". You could subscribe to the 'filter' event of the Kendo UI Grid and override the default filtering logic as per the example below:
$("#grid").kendoGrid({
...
filter: function(e) {
e.preventDefault();
var grid = e.sender;
var updatedFilters = [];
var fieldFilter = e.filter; //get the selected filter expressionvar currentFilters = grid.dataSource.filter(); //get the applied data filters, if anyif(currentFilters) {
$.each(currentFilters.filters, function(i,v){ //get the current filter expressions and store them in an array
updatedFilters.push(v);
});
if(fieldFilter) { //get the selected filter expression and store it in the array
updatedFilters.push(fieldFilter.filters[0]);
}
grid.dataSource.filter({}); //reset the data filters
grid.dataSource.filter({filters: updatedFilters, logic: "or"}); //apply the new filter espressions with logic "or"
grid.dataSource.filter(); //filter the grid's data
} else {
grid.dataSource.filter(e.filter);
}
}
});
You could apply a customized filter logic only for specific columns and keep the default one for the others.
Here is a Dojo sample where the columns "Freight" and "Ship Name" are filtered with the logical operator "OR".
If you have any questions, don't hesitate to let me know.
Regards,
Mihaela Lukanova
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.