How to search across multiple columns?

How to search across multiple columns?

ibokatibokat Posts: 5Questions: 4Answers: 0

I want to search for a specific text in 2 different columns. Basically does the keyword "hamster" appear in column 1 or 6 and display the results. But I cannot figure out how that is working.

I have tried the following but it does not appear to work.

table.columns([1,6]).search("hamster").draw();

whats the right approach?

Answers

  • allanallan Posts: 63,602Questions: 1Answers: 10,486 Site admin

    At this time that will result in a search on "hamster" on both columns 1 and 6 - an AND operation.

    To do an OR search like that, you'd need to use a function (something which was introduced in the recently released 2.0.0). e.g.:

    table.search.fixed('myFunc', (row, data) => {
        return data[1] === 'hamster' || data[6] === 'hamster';
    });
    

    Note I've assumed the use of array based data there, change if you are using objects, and also I've used the new search.fixed() so the end user can still use the global search.

    Allan

Sign In or Register to comment.