search() in multiple columns

search() in multiple columns

BennofueBennofue Posts: 1Questions: 1Answers: 0

I have a DataTable with multiple columns.
Some of them are hidden, as they contain translations for the data into different languages.
For every shown (visible) column there is an input to filter the table by a specific value.

The filter like this works perfectly fine, if the value is in the shown (visible) column:

$('input', this).on('keyup change clear', function() {
      if (table.column(10).search() !== this.value) {
           table.column(10).search(this.value).draw();
      }
});

Let's pretend that column 14 contains the translation of column 10 - but column 14 is not visible.
If the user is trying to filter with the input in column 10, I also want to search in column 14, since it contains the translation.
The following code doesnt work for me, since the searched value has to be in column 10 AND column 14.

$('input', this).on('keyup change clear', function() {
     if (table.column(10).search() !== this.value) {
          table.column(10).search(this.value).table.column(14).search(this.value).draw();
     }
});

Is there a way to display (draw) rows if the value searched in column 10 is either in column 10 OR column 14?

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    This is an example that Kevin did a while back, I'm not sure which thread it came from now, but it's showing how a custom search can provide OR logic.

    Colin

This discussion has been closed.