Search Multiple results

Search Multiple results

mattbrownmattbrown Posts: 5Questions: 1Answers: 0

Hi EveryOne I am new to datatables hence want to ask a simple question:
('#example').dataTable({"search": {regex: true}}).search("London|Tokyo", true, false ).draw();
when i do this I get perfect results but I dont want to put hardcoded data but the dyanamic one that comes from search box.
In case of Dynamic Values it only searches for value before "|" character.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    See if this example helps:
    https://www.datatables.net/examples/api/regex.html

    Kevin

  • mattbrownmattbrown Posts: 5Questions: 1Answers: 0
    edited June 2018

    I tried Based on link you gave but didn't get results
    function filterGlobal () {
    $('#example').DataTable().search(
    $('#global_filter').val(),
    true, false
    ).draw();
    }

    $(document).ready(function() {
    $('#example').DataTable();
    $("#example_filter input").prop( 'id','global_filter' );
    $('#global_filter').on( 'keyup click', function () {
    filterGlobal();
    } );
    });

  • mattbrownmattbrown Posts: 5Questions: 1Answers: 0

    I dont want to create a new search box but use the default one

  • mattbrownmattbrown Posts: 5Questions: 1Answers: 0

    Hey Kevin thanks for that link it solved my issue but just wanna ask if instead of "|" can If I want to use "," is that possible....
    Many thanks you are saviour

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765
    Answer ✓

    Yes you can. Maybe you can take $('#global_filter').val() and replace the , with | and perform the search.

    I've used the search plugin for this type of search. It may be a good option for you depending on the complexity of what you are trying to do:
    https://datatables.net/manual/plug-ins/search

    Kevin

  • mattbrownmattbrown Posts: 5Questions: 1Answers: 0

    That's good idea thanks...

This discussion has been closed.