I want to hide some columns in datatable when page change size (responsive). I would like to show/hide some columns depending on curremt size.
Thank you.
I want to hide some columns in datatable when page change size (responsive). I would like to show/hide some columns depending on curremt size.
Thank you.
It is very simple.
var tbl = $('your_datatable_selector');
// Work with column 2
tbl.DataTable().column(2).visible(false); // or true, if you want to show it
Use Responsive extension to show/hide columns dynamically based on screen size.
Optionally you can determine which columns will be hidden first using responsivePriority option, see Column priority for more details.
Alternatively you can assign special classes to th elements to define column behavior, see Class logic for more details.
You just need to include additional CSS/JS files and use responsive option as shown below.
$('#example').DataTable( {
responsive: true
} );
{
var table = $(`'#screenFieldsTable'`).DataTable();
// Hide two columns
table.columns( [10,11] ).visible( false );
}