Inconsistent search() behavior
Inconsistent search() behavior
gyrocode
Posts: 126Questions: 6Answers: 30
See this jsFiddle for demonstration.
The following code returns all rows with London
in any column.
table.search('London', false, true).draw();
The following code (looking for exact match in the column using regular expression) returns no rows:
table.search('^London$', true, false).draw();
However this code works:
table.column(2).search('^London$', true, false).draw();
It seems inconsistent that when using regular expression the same logic is not applied, i.e. include a row if at least one column matches the search string.
This discussion has been closed.
Answers
I see your point, however, the global search is across all columns, and the way DataTables implements that is to have a string string that contains the data for all columns and run a regex on that - hence there is only one start and end, not multiple start and ends for each column.
This is done for performance reasons - performing its smart search on individual columns would be horrible (although I realise you've disabled smart search here, the same string is used as the global search source).
Allan
Thanks for explaining, Allan, the behavior makes sense now. But it still seems inconsistent.
Ultimately, I was looking for simple solution to perform exact search within each column and display rows where at least one column matches. Guess it will be not as simple as I thought.