简体   繁体   English

具有响应式扩展的DataTables列可见性

[英]DataTables column visibility with Responsive extension

I am quite new in jQuery DataTables. 我是jQuery DataTables的新手。 I just read about responsive table feature provided by DataTables, see this example . 我刚刚阅读了DataTables提供的响应表功能,请参阅此示例

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? 我们可以定义哪些列必须隐藏在不同的窗口大小上吗?

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. 其中columnDefs.targets设置为-1指向最后一列(列索引从右侧开始计数), className: 'all'表示该列始终可见,无论浏览器宽度如何。

If you can edit the HTML, you can add the data-priority="1" attribute to the th element you want NOT to be hidden. 如果你可以编辑HTML,您可以添加data-priority="1"属性来th你想不被隐藏的元素。 Ex: 例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM