search() for all matches to either one of two values?

search() for all matches to either one of two values?

bricollbricoll Posts: 3Questions: 1Answers: 0
edited January 2017 in Free community support

Is there a way to use search() to return all matches for either of two (or more) values?

Example: Return all rows matching either "knowledge" or "processes"?

This question has an accepted answers - jump to answer

Answers

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

    One option is to use regex searching as in this example:
    https://datatables.net/examples/api/regex.html

    If you choose regex and type tokyo|london it will show rows with both tokyo and london.

    Kevin

  • bricollbricoll Posts: 3Questions: 1Answers: 0

    Is there a way to use that regex parameter as part of a function like the one below? (The function is invoked onclick of a dropdown menu item.) Reference manual doesn't provide quite enough info on search() for me to see precisely how the parameters work.

    var table = $('#myTable').DataTable();
    
    function myFunction() {
        table
            .columns(2)
            .search()
            .draw();
    
    }
    
  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    Answer ✓

    You can enable regex during initialization:
    https://datatables.net/reference/option/search.regex

    Or through the API:
    https://datatables.net/reference/api/search()

    Kevin

  • bricollbricoll Posts: 3Questions: 1Answers: 0
    edited January 2017

    Thank you so much, Kevin!

    This worked:

    function myFunction() {
        table
            .columns(2)
            .search('knowledge|processes', true, false)
            .draw();
    
    }
    
This discussion has been closed.