Trying to only display exact matches to the search term entered in the search bar.
For instance, I have a search bar that filters by ID#. I want only records that match the exact # entered to display.
So if 123
is entered, I don't want 12345
, 91239
, etc etc to be displayed. Only 123
.
Saw some info about bRegex
on the FAQ page, but it's not working for me. Any ideas?
You can use regular expression for exact matching as following:
The syntax of the
search
function is:We disable smart search in this case because
search
function uses regular expression internally when smart search is set to true. Otherwise, this creates conflict between our regular expression and the one that is used bysearch
function.For more information, check out the following documentation from DataTable:
column().search()
Hope it's helpful!
Try using the bSmart option and setting it to false
From the documentation
UPDATE
I found this:
at this link http://www.datatables.net/forums/discussion/4096/filtering-an-exact-match/p1
looks like you can set
bSmart
andbRegex
per column as well as specifying a manual regex per column.Ok solved the problem. However, since the column I am using the exact match on sometimes contains multiple ID #s seperated by commas, I wont be able to use an exact match search.
But for those interested, here is the answer:
The current versions of Datatables supports using real exact matching on a column basis.
The documentation explains each flag.
Where
filter_value
is the string entered in the filter field.table.column(col_num).search(filter_value + "$", true, true, false).draw();