How do I add regex functionality to the search bar?
How do I add regex functionality to the search bar?
I'm currently on Datatables 1.10.4. I have several datatables on my website. I would like the search bar to have regex functionality. So what I've done is I've added the search property like this:
search: { regex: true }
However, I would also like to save the state of the datatable until the search string is cleared. So I also have:
stateSave: true,
stateDuration: 7200
I found that when stateSave is true, regex doesn't work. When it's false it works. I can't find any information on why they're related, but the problem gets stranger than that. I've messed around with it for so long and these are the only things that I'm changing, but sometimes it works and sometimes it doesn't. Right now, I have all the datatables with the above properties and values and they're all working as they should, but just yesterday half of them weren't working with the same code.
Are these even related? What properties might make the regex search not work?
Answers
I haven't used state save much but I don't see why one would affect the other. However DT 1.10.4 is pretty old so there may be issues I'm not aware of.
The
search()
doc recommends that if using regex search you should disable smart search. So you may want to try this:```
search: {
regex: true,
smart: false
},
If disabling smart search doesn't help then maybe you can post a link to your page or provide a test case with specific searches that aren't working.
Kevin
Hey Kevin, thanks for the answer. I have been disabling smart search along with enabling regex, but it doesn't seem to have any effect honestly. The data from these tables is coming from a datatabase using PHP, I'm not sure if that would have any effect on it or not.
I'll see if I can provide a test case, thanks!