Reputation: 21
How can I show and hide columns in datatable.js you see I can enable and disable it BUT the problem is my datable is binded in AJAX source so it automates requests each time I show and hide a column.
Below is the code I used but has no luck in showing and displaying columns without an ajax request.
$(".table-dash1").dataTable().fnSetColumnVis(0, false);
Upvotes: 1
Views: 2342
Reputation: 307
An example from the DataTables documentation:
$(document).ready(function() {
$('#example').dataTable( {
"sScrollY": "200px",
"bPaginate": false
} );
} );
function fnShowHide( iCol )
{
/* Get the DataTables object again - this is not a recreation, just a get of the object */
var oTable = $('#example').dataTable();
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
Hope this helps.
Upvotes: 1