This is a migrated thread and some comments may be shown as answers.

is it possible to configure grid using Or statement for multi-columns filtering?

2 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
Aleksandr asked on 15 Apr 2021, 01:28 PM
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

Sort by
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 expression
    var currentFilters = grid.dataSource.filter(); //get the applied data filters, if any
    if(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".

https://dojo.telerik.com/OsoleMEM/2

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/.

0
Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
answered on 20 Apr 2021, 10:39 AM

Mihaela Lukanova,

thx a lot for the reply, this is exactly what i want 

Thx Alex

 

 

Tags
Grid
Asked by
Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
Answers by
Mihaela
Telerik team
Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
Share this question
or