My first post on Stack Overflow. :)
I have a jQuery DataTable, with a custom dropdown "Hide/show columns" with checkboxes. These are working perfectly. But when I hide a column, I also want it to not be searchable. When I show it again, I want it to be searchable again. Is this possible?
Here is my code:
$('input[type="checkbox"]', $("#myHideShowDropdown")).change(function () {
// data-column is just the number of the column
var column = oTable.column($(this).attr("data-column"));
column.visible(!column.visible()); // This works
// Here I want to to something like
// column.searchable(!column.searchable())
// but there is no such thing
});
SOLUTION
To toggle column filtering along with visibility, use the code below:
$('input[type="checkbox"]', $("#myHideShowDropdown")).change(function () {
var colIdx = $(this).attr("data-column");
var column = oTable.column(colIdx);
var isVisible = column.visible();
column.visible(!isVisible);
oTable.settings()[0].aoColumns[colIdx].bSearchable = !isVisible;
oTable.rows().invalidate().draw(false);
});
DEMO
See this jsFiddle for code and demonstration.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments