How to limit the search to "equals" and not "like" at the time of initialization?
How to limit the search to "equals" and not "like" at the time of initialization?
I am using DataTables 1.10.25 with server-side processing, I am trying to limit a column to display items matching a specific value for that column. I tried it with search builder but later found out that it's not supported yet. So I moved on to using searchCols. It got me close to what I wanted to do but the problem is that it matches the keyword with "Like" and so it brings back all similar results as well. I wanted it to be matching the keyword exactly. The column is an integer so if I search for 2 it would bring back results for 2, 22, and 12 as well. I tried using regular expression and it didn't work at.
Here's how I am using it:
searchCols: [
null,
null,
{ sSearch: '2'},
null,
],
Answers
That's right, the supplied server-side scripts don't support regexes for performance reasons. However, there are a few threads on this forum. such as this one, that offer solutions,
colin
Here's the work around that I created:
I created a copy of filter method in the SSP class as customFilter and changed a certain fragment to this code below:
And then passed the number as { sSearch: '=12'}. This got the job done but now I want to change the Jquery code to recognize some like { sSearch: '12' , matchType: "equals"} so that it gets passed to $requestColumn variable on the server side. Can anyone point me to the part that I need to modify? Also, would it be a good idea to commit my addition to the repo?
You would use
ajax.data
to modify the data structure DataTables sends to the server.Including it with the script - it is something that we'll consider. There are a few other options such as
startsWith
that we've been thinking about as well, and this would fall under that umbrella.Allan