Or (logical expression) Search

Or (logical expression) Search

sr57sr57 Posts: 11Questions: 3Answers: 0

Hello All,

By default, datatable uses "And Search", if we enter 2 words, it filters the records contaning both words.
I want to display the records containing one of the two words or more generally to follow a more complex logical expression.
I know that we can overide the standard search by a specifiq search but does someone know if there is any already done solution?
Thanks in advance.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Do you want the OR search within a column or across all columns in the row?

    If within a column you could use column().search() as a regex search. You can take the multiple words and separate them with | for an or regex search. I don't have nay handy links but there are some threads on the forum with this type of solution. Also see this example.

    If the OR search is across columns you can use a search plugin. See my last example in this thread. There are other examples in other threads.

    Kevin

  • sr57sr57 Posts: 11Questions: 3Answers: 0

    Hi Kevin @kthorngren

    My question was about global OR search, thank you for your complete answer.

    I tested your example, but I would have not understood st, it seems to word as AND

    For instance, if choose as search filter "ai j" , it returns only "Jena Gaines Office Manager"

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    Answer ✓

    I tested your example, but I would have not understood st, it seems to word as AND
    For instance, if choose as search filter "ai j" , it returns only "Jena Gaines Office Manager"

    Are you referring to this example?
    https://datatables.net/examples/api/regex.html

    For this example to work you will need to type in the regex expression. It won't convert the space to a |. Like this:

    Kevin

  • sr57sr57 Posts: 11Questions: 3Answers: 0

    Thanks I looked a wrong one http://live.datatables.net/zarolake/1/edit

    I'll see https://datatables.net/examples/api/regex.html

    later; Thanks for your quick answer.

  • sr57sr57 Posts: 11Questions: 3Answers: 0

    Thanks you very much @kthorngren for your complete example.

    Regex is really the ultimate solution :)

    For my OR test ; ai|j

This discussion has been closed.