I need to show and hide the columns of the datatable after doing a javascript test, but it doesn't work good.
This is my test javascript:
if ( $('#commune_to_display').val()==""){
$('#utable td:nth-child(2)').hide();
$('#commune_to ').hide();
}
This test works just in the first page of the datatable, after pagination the column is still visible.
How can I fix it? thanks for help
To hide and show columns use columns() and visible() method. Call it on dataTables instance and pass column index in columns() method and false to visible() method. Similarly, pass true to visible() if you want to show the columns.
DataTable(); //hide the first column dt. column(0). visible(false); To hide multiple columns, columns().
aoColumnDefs: This array allows you to target a specific column, multiple columns, or all columns, using the aTargets property of each object in the array (please note that aoColumnDefs was introduced in DataTables 1.7).
how to get the dynamic column header and result from ajax call in jquery datatable. var $table=$('#MSRRes'). dataTable( { "bFilter": false, "bDestroy": true, "bDeferRender": false, "bJQueryUI": true, "oTableTools": { "sSwfPath": "swf/copy_cvs_xls_pdf.
You can show/hide columns as shown below. Just replace 3
and 4
with your actual column indexes.
var table = $('#utable').DataTable();
table.column(3).visible(true); // To show
table.column(4).visible(false); // To hide
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With