escapeRegex escapes periods in ip address searches causing no results
escapeRegex escapes periods in ip address searches causing no results
I use the following for a custom search box. Datatables is NOT serverside in this case. I found that search was not working for a column that shows ip addresses and after some digging realized it was escapeRegex causing the problem - I think.
selectSearch.keyup(function() {
dt.search( $.fn.dataTable.util.escapeRegex(selectSearch.val()) ).draw();
console.log( $.fn.dataTable.util.escapeRegex(selectSearch.val()) );
});
If I search for 111.111.111.111
the console after going through escapeRegex prints out 111\.111\.111\.111
and it does not find any matches. If I remove escapeRegex it does find the matches.
What is the solution here? Certainly someone else must have come across something similar before. The search should be escaped, but if the escaped version doesn't find the correct match then what should I do here? Modify the data of my ip address column with a display/default switch so the default matches the 111\.111\.111\.111
format? This also has me wondering what other searches are not working properly when I am not using serverside that I might not have noticed yet.
Answers
The intention of
$.fn.dataTable.util.escapeRegex()
is to work with regex searches. Your search is using the default smart search mode. Take a look at thesearch()
docs for more info about the modes. Trey this:See this example:
http://live.datatables.net/hepitegi/1/edit
Kevin