Search exact match
Search exact match
sylapal
Posts: 1Questions: 0Answers: 0
Hi
I'm using DataTables thru the WordPress plugin. My website shows a huge list (4700+ entries, 4 columns) and I want to filter it with the search box. However, it works with a “contains” and I would like an “exact match”. I don't see any option for that.
I contacted the author of the plugin and he can't help me saying that the DataTables JS library is in cause.
Is there any possibility to set search for "exact match" ?
This discussion has been closed.
Replies
You can use regex search and enclose the search string between
^
(beginning of line) and$
(end of line). You can try the example here:https://datatables.net/examples/api/regex.html
Check the Regex option for Name and uncheck smart search. Enter
^$
and you will have no matches. Then enter^bruno
you will matchBruno Nash
. Add the$
at the end for^bruno$
and there are no matches. Then type^bruno nash$
and you will have a match.Kevin
Below stuff worked for me.
var searchTerm = this.value.toLowerCase(),
regex = '\b' + searchTerm + '\b';
table.rows().search(regex, true, false).draw();
link
https://jsfiddle.net/hmjnqjbs/3/