columns().search() question
columns().search() question
ewmanthei
Posts: 14Questions: 1Answers: 2
The following code will find data within both columns 0 and 2. How can I find data within either columns 0 OR 2?
oTable.columns([0,2]).search(loadSearch, true).draw();
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Unfortunately there is no API for that in DataTables at the moment. As you are seeing it applies the same filter to both selected columns.
Being able to define a custom group of columns is something I'm looking into for the next major version of DataTables. The "global" search (i.e. all columns) is then just a special case of that. I have a slight concern about memory consumption (since its an extra array) and performance( since invalidation has another array to handle), but I think it is worth exploring.
For now you would need a custom plug-in.
Allan
Allan,
Thanks for the help. Could it be done somehow this way (either currently or in the future)?
Start with:
then perform something like this:
A potential benefit of this method is being able to preferentially decide which column(s) you want to be given priority in the search results. In my case, I'd like to be able to have column 0 searched first and its results displayed at the top prior to going to column 2.
In future, as I say, I want to allow grouping of search columns and that will allow what you have above to just automatically work.
There is currently only the option of using a custom search plug-in to do it.
Allan
For what it's worth, I resolved this by switching to server side processing and manipulating the data within php. I'm still running from a flat json file so there's no unnecessary db calls, but php allows me to restructure the data object however I want more easily and then send it back.
Cunning - thanks for posting back, and good to hear you have it working the way you need.
Allan