How to filter hidden column by dropdown value but ignore column in global filter?
How to filter hidden column by dropdown value but ignore column in global filter?

This may be a repost. I'm not sure what happened but my other thread I posted a few minutes ago with the same title just disappeared.
Link to test case:
http://live.datatables.net/xozatito/1/edit (I actually use AJAX but can't figure out what data to call in the test case)
Debugger code (debug.datatables.net):
Error messages shown:
No error messages.
Description of problem:
I have a dropdown that on-change calls FilterBannedPeople
and searches the first hidden column for the value that was selected. The column must be hidden and also not searchable by the global filter. The only way to filter records by that column would be using the dropdown. The column name is "Banned" and each record either has the string "true" or "false" as its data.
I'm unable to implement what I just described because if I I disable the global filter from searching the hidden column using "searchable": false
, it also disables searching the individual column using the API in the FilterBannedPeople function. I really just need a dropdown that can filter rows based on the dropdown selection (if "Banned" is selected then all rows with "true" in Banned column should appear), but I want the global filter should ignore that column.
As I mentioned, I actually use AJAX to populate the data so maybe there's a way to use the JSON values from the data
object instead of actually having the Banned column on the front-end?
This question has accepted answers - jump to:
Answers
I think the easiest way is to create a Search Plugin. You can leave the column hidden and with searchable false or remove it from the table. The plugin has the
searchData
parameter and therowData
parameter. You will need to use therowData
parameter for the comparison. I updated your example to show this:http://live.datatables.net/xozatito/4/edit
Kevin
Kevin, thanks so much. The search is behaving as I wanted. However, I am wondering will this plug in apply globally to all datatables? I have other datatables in the app (will be able to test tomorrow) and I'm wondering if it will affect their filter as well. I call
draw()
at least on one of them.You can use
settings.nTable.id
to limit the tables the plugin runs against. See the example in this thread.Kevin