DT Searching for multiple values in a column
DT Searching for multiple values in a column
jLinux
Posts: 981Questions: 73Answers: 75
I was trying to use the column().search()
method to search a column for some values, but I wanted to search for multiple values.
I know it takes regex, so I could just do something like table.column(1).search( new RegExp( '(' + values.join('|') + ')' ) )
, but I was trying to avoid that. But if thats the only solution, then thats fine
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
It doesn't (yet) actually. You can pass a string in, which has a regular expression in it, but you can't pass in a native RegExp instance (if you can't that isn't documented or supported and only works accidentally!). That is something that will be coming with the next major version of DataTables (although I've just to figure out how to make it work with state saving).
There are basically two options for what you want at the moment:
Allan
I try to avoid using regex for things like this. I would be ok with writing a custom filter, but Id like to have the search applied only when the search button is clicked. It looks like the filter in that example is executed every time
draw()
gets called.. The problem with that is if they havent clicked the search button, but something else triggers a draw(), then the filter will be implemented..You would need to have some conditional logic in your filter that would "know" if the button has been pressed or not. Alternatively, you could only add that custom filter to the array when the button is pressed, and remove it again if needed in future.
Allan