How do you search a whole string for whole terms?
How do you search a whole string for whole terms?
I'm using a multiple input type text search with "|" as separator, this is the code:
table.columns(1).search($(this).val(), true, true).draw();
I've noticed that the first term is being searched in the whole string, from the second term i will only have a match at the beginning of the string.
A practical case:
In this column i have:
TEGR1501
[...]
TEGR2001
typing "1501|2001" will only return "TEGR1501" while typing "1501|TEGR2001" is returning both "TEGR1501" and "TEGR2001".
How can i search the whole string for the whole terms?
Replies
The documentation for .search says not to use "true, true" parameters in combination. One of those should be false.
I don't like requiring my users to remember the pipe symbol, so I use this to make spaces work like pipes.
I'm not sure how to get whole words. In my quick testing, the \b markup in a reg ex should be a boundary indicator, but DT doesn't like it.
I should have searched for this (you should have too ) - The answer was the first thing that came up in the search.
This works for a whole word search, with space separators. I needed to escape my \b entries.
Hi thom and thanks for your reply. I maybe express myself in a not clear way and i'm sorry. The method you suggested works only if you type in the whole word for all the therms but i need to filter also by partial word IN ALL TERMS. Problem in fact is that the partial string matches ONLY ON THE FIRST WORD, from the second on the match is fired only if the string match at least the beginning of the strings in the table.
So i make some new examples:
This is table content i have:
TEGR1501
[...]
TEGR2001
actual behaviour (BAD):
typing "1501|2001" i get only "TEGR1501"
typing "1501|TEGR2001" i get both "TEGR1501" and "TEGR2001"
desired behaviour (OK):
typing "1501|2001" and getting both "TEGR1501" and "TEGR2001"
as well as
typing "1501|TEGR2001" and getting both "TEGR1501" and "TEGR2001"
as well as
typing "TEGR1501|TEGR2001" and getting both "TEGR1501" and "TEGR2001"
And thanks for your suggestion on the separator!
Ouch, the solution was to set the second parameter to false! My bad i didn't read good enough. Thanks for your help Thom!