Filter with space and OR condition

Filter with space and OR condition

valouvalou Posts: 1Questions: 1Answers: 0

I have a table that contains a list of locations that I want to filter with a OR condition.
I manage to make the OR condition working using a "|" between every words and setting up "regex" as true.

$('table').DataTable({
          "pageLength": 20,
          "language": {"info":           "Showing _START_ to _END_ of _TOTAL_"},
          "search": {
            "regex": true,
                  }
});

However it seems that I have some issue with locations that contain a space in their name such as "Hong Kong" or "Abu Dhabi".

For instance if #DataTables_Table_0_filter contains "Hong Kong|Paris" it is working but "Paris|Hong Kong" doesn't work.

I tried to escape the space, using a %20, double-quotes... without success.

If someone can help me it would be great!

Answers

  • WilliamVoWilliamVo Posts: 1Questions: 0Answers: 0

    Dear Allan,

    Can you please help to answer this question?

    I'm new to DataTables search regex and I have the same problem. For example, I have columns with Paris, London and then Hong Kong.

    I choose Paris and Hong Kong from my multiple select then the regex I build is "Paris|Hong Kong". The search result will be displayed for rows with Hong Kong only and it ignores Paris. It means it performs search for (Paris OR Hong) AND Kong?

    I need it performs search for Paris OR (Hong AND Kong).

    How should I build my regex to work with DataTables search API?

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736

    Maybe this example will get you started:
    https://datatables.net/examples/api/regex.html

    You should make sure to turn off smart searching when doing regex searching. If you try the Office column search with both regex and smart and the search phrase london|new york you will see only New York. But if you use only regex then you will get both. That might be the problem.

    If you can't solve it then please post a test case showing what you are trying to do.

    Kevin

This discussion has been closed.