Search by words separated by comma or space

Search by words separated by comma or space

artem4ik19artem4ik19 Posts: 10Questions: 2Answers: 0

Hello everyone.
I have a table with some data,
and i want to have ability to make search like enter to names of cities like Paris Berlin so it will show result based on separated words

Hope you can help me
Thanks

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 1,542Questions: 0Answers: 285

    Hi @artem4ik19 ,

    You can do this with a regular expression search - take a look at the search examples here. On the top search, check "Treat as regex" and enter "(tokyo|london)" (without quotes) and both will be matched.

    As this isn't intuitive for the average user, you should create your own search input element (as in the example) and just generate your own regex before submitting to search().

    Hope that helps,

    Cheers,

    Colin

  • artem4ik19artem4ik19 Posts: 10Questions: 2Answers: 0

    @colin thanks

    i created inputwith id global_filter and added function on keyup for it
    jQuery('#example').DataTable().search(jQuery('#global_filter').val(),true,false).draw();

    but it doesnt work when I input two cities
    https://datatables.net/reference/api/search()#Example here no normal example, also was searching in internet and no info how to realize this functionality =(

  • colincolin Posts: 1,542Questions: 0Answers: 285

    Hi @artem4ik19 ,

    Take a look at this example here - I think this will do what your'e after. Here, if you enter "London Edinburgh" it will show only those two values.

    Hope that helps,

    Cheers,

    Colin

  • artem4ik19artem4ik19 Posts: 10Questions: 2Answers: 0

    @colin I copied full code on my site and it works
    But when I use my own data from mySQL
    It doesnt woek. So maybe it works only with static data?
    http://backup.primoportal.de/marktanalysen/gewerbeimmobilien/ example

  • colincolin Posts: 1,542Questions: 0Answers: 285
    Answer ✓

    Yep, the demo server-side scripts don't support regex searches, as it is expected the data set will be too large and this would cause a performance issue.

    If your data set isn't large, you could disable serverSide, and then the search would work. It really depends on how much data you have, or expect to have in the future.

    Cheers,

    Colin

  • artem4ik19artem4ik19 Posts: 10Questions: 2Answers: 0

    @colin THank you so much for help. Now it works :) :)

Sign In or Register to comment.