[bug ?] strange difference between global search and column search
[bug ?] strange difference between global search and column search
Hello,
I think I may have discovered a bug in global search... or there is something i really can't understand...
Please have a look at this example page :
https://datatables.net/examples/api/regex.html
Check the checkbox "Treat as regex" and UNcheck "use smart search" for both "Global Search" and "Column - Position".
Try to write nt$ in the "Column - Position" input field and it shows rows with "Accountant", "Junior Technical Author", ... which seems right.
Now, empty the field "Column - Position" and write the same think : nt$ in the "Global Search" input field ==> the table is empty now... Why ??
Thank you very much for your help...
T.
Answers
The global search works on a string concatenation of all columns. So
$
for the end would only match the last column's data, not some arbitrary point in the string.\b
could be used to match the end of a column's data.Allan
OK I understand. But then, how can I make a global search to find the rows where a CELL ends by "nt" ? The regexp "nt\b" also matches cells which contains "sdfnt sdfsdf" and I don't want this...
Thanks again !
Try
nt
(double space). The column search strings are concatenated using a double space. The only other option is to use a custom search.Allan
Well... Sorry : regexp are quite new for me. If I would like to match only rows which contains cells which ENDS by nt, what regexp should I use ? (and same question for "BEGINS with nt")...
/nt[ {2}\b]/
should do it (remove the leading and trailing/
's - I included them just to be clear that's a regular expression.Allan
Thank you very much but... it does not seems to validate what it should. Please have a look here : https://regex101.com/r/zV7aS3/1
According to what I understood, the regexp should find "nt5" and "nt8xxxx" but it finds only "nt2" and does not find "nt5" nor "nt8xxxx"...
I don't think it should find
nt5
ornt8xxxx
. You said above:Neither of the above two end in
nt
, so it doesn't match them (odd that it matchesnt2
).You might want to consider asking someone with more regex expertise than myself!
Allan
Oups, sorry... I make that mistake because I will have the same question for finding a regexp which match a row if contains a cell which begins with nt.
Here, please have a look to https://regex101.com/r/zV7aS3/2
Your regexp matches "aménagement" and "bont" but should'nt (amho) since it's not followed by two spaces... The only word I expect regexp to match would be "rangement" in this situation, isn't it ?
In this case
nt(\s{2})
should do the trick.Thank you ! I disabled Smart Search and tried both suggestions in the global search at the top of the table : it does not seems to work...
Using Allan's suggestion [ {2}\b] first : nt[ {2}\b] finds a row with a cell "BROL-LAURENT (word)". The regexp ux[ {2}\b] also shows a row with a cell "BERTAUX another word". I don't want this because nt / ux does not ends the cells...
Using F12Magic suggestion (\s{2}) now : nt(\s{2}) and ux(\s{2}) does not show the previous problematic rows (which seems good) but "rk(\s{2})" does not show a row which contains a cell ending by "Mark"...
Allan, are you really sure that the columns are concatenated with double space for global search ? I'm using 1.10.7.
Quite certain.
Weird - it shouldn't. Running
"BERTAUX another word".match( /ux[ {2}\b]/ )
on your browser's console will show it doesn't match.Allan
In my browser's console, it matches (added 'gi' for global search and insensitive) :
It also matches here without gi flags :
https://regex101.com/r/zV7aS3/3
How about this then: /(ux|\s{2})/gi
Well, it also matches all double spaces " " ; just have a look here : https://regex101.com/r/zV7aS3/4
Don't know if the following is completely correct regex, but it does seem to do the job you want to accomplish.
Try: (nt)(?(1)\s{2}|.)|nt$
https://regex101.com/r/zV7aS3/6
Yes, it seems :-) I will try to put it inside my code to use it with my datatable and I will tell you...
Now I will look for a regexp which will look for a given string at the beginning of a cell in global search. Thus if I understand correctly what Allan is saying, if I search all cells which begins by "BER", the regexp should match "BER" and " BER" (two spaces followed by BER" but not " BER" (one space followed by BER). Could you please help me ?
Hi,
that seems to be a bit easier. How about ^(ber)|(\s{2}ber)
https://regex101.com/r/zI5bG9/1