Is there a way with the jquery datatables plugin to hide (and show) a table column?
I figured out how to reload the table data: using fnClearTable
and <
For anyone using server-side processing and passing database values into jQuery using a hidden column, I suggest "sClass" param. You'll be able to use css display: none to hide the column while still being able to retrieve its value.
css:
th.dpass, td.dpass {display: none;}
In datatables init:
"aoColumnDefs": [ { "sClass": "dpass", "aTargets": [ 0 ] } ] // first column in visible columns array gets class "dpass"
//EDIT: remember to add your hidden class to your thead cell also
if anyone gets in here again this worked for me...
"aoColumnDefs": [{ "bVisible": false, "aTargets": [0] }]
$(document).ready(function() {
$('#example').DataTable( {
"columnDefs": [
{
"targets": [ 2 ],
"visible": false,
"searchable": false
},
{
"targets": [ 3 ],
"visible": false
}
]
});});
Hope this will help you. I am using this solution for Search on some columns but i don't want to display them on frontend.
$(document).ready(function() {
$('#example').dataTable({
"scrollY": "500px",
"scrollCollapse": true,
"scrollX": false,
"bPaginate": false,
"columnDefs": [
{
"width": "30px",
"targets": 0,
},
{
"width": "100px",
"targets": 1,
},
{
"width": "100px",
"targets": 2,
},
{
"width": "76px",
"targets": 5,
},
{
"width": "80px",
"targets": 6,
},
{
"targets": [ 7 ],
"visible": false,
"searchable": true
},
{
"targets": [ 8 ],
"visible": false,
"searchable": true
},
{
"targets": [ 9 ],
"visible": false,
"searchable": true
},
]
});
});
With the api you can use
var table = $('#example').DataTable();
table.column( 0 ).visible( false );
Look this info:
enter link description here
You can try as below to hide/show dynamically runtime
Hide :
fnSetColumnVis( 1, false, false );
Example: oTable.fnSetColumnVis(item, false,false);
Show :
fnSetColumnVis( 1, true, false );
Example: oTable.fnSetColumnVis(item, false,false);
Here, oTable is object of Datatable.