Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTables column visibility with Responsive extension

I am quite new in jQuery DataTables. I just read about responsive table feature provided by DataTables, see this example.

Here columns are hiding on window resizing but the problem is that last column is also hiding. Can we define which column must be hidden on different window sizes?

like image 695
Kenny Avatar asked Feb 09 '23 04:02

Kenny


2 Answers

See Class logic for fine-grained control on when each column would be visible.

For example, to always show last column:

$(document).ready(function(){
    $('#example').DataTable({
       responsive: true,
       columnDefs: [
          targets: -1,
          className: 'all'
       ]
    });
});

where columnDefs.targets set to -1 points to last column (column index counting from the right), and className: 'all' indicates that column will always be visible, regardless of the browser width.

like image 127
Gyrocode.com Avatar answered Feb 13 '23 05:02

Gyrocode.com


If you can edit the HTML, you can add the data-priority="1" attribute to the th element you want NOT to be hidden. Ex:

<th data-priority="1">Last column</th>

like image 41
tabacitu Avatar answered Feb 13 '23 07:02

tabacitu