jQuery DataTables - 响应式 Table 与 ScrollY 不工作

jQuery DataTables - Responsive Table with ScrollY is not working

我正在使用具有响应式 Table 的 DataTables 插件并修复了 yScroll 并禁用了 xScroll。

但是我仍然得到水平滚动条,尽管我添加了如下代码...

scrollY: 200,
scrollX: false,

Screenshot Ref:

反正我用的是Responsivetable,为什么要显示Horizo​​ntal Scrollbar?

因此,展开/折叠列功能也不起作用...

请参考下面的代码、在线示例和截图...


Online Demo


CSS

th,td{white-space:nowrap;}

如果我删除上面 css 它会按预期工作。但我不想总结 td / th 文本。这就是我面临的问题:(

jQuery:

$(document).ready(function() { 

  var table = $('#example').DataTable( {
    dom: 'RCT<"clear">lfrtip',

    scrollY: 200,
    scrollX: false,

    columnDefs: [
      { visible: false, targets: 1 }
    ],

    "tableTools": {
      "sRowSelect": "multi",
      "aButtons": [
        {
          "sExtends": "print",
          "sButtonText": "Print"
        }
      ]
    }

  });
});

HTML

<table id="example" class="display responsive" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>

    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>0,800</td>
        </tr>
.....................

className: 'none' 添加到您的 columndefs

columnDefs: [
  { className: 'none', targets: 1 }
]

响应式插件和可见性隐藏选项之间似乎存在冲突。

将此更改为:

columnDefs: [
  { visible: false, targets: 1 }
],

收件人:

columnDefs: [
  { targets: 1 }
],

然后水平滚动条消失了。

工作叉: http://cssdeck.com/labs/qfeibp13

如果您使用的是响应式,则响应式将决定列的可见性。如果您不希望显示特定列的数据,请使用“从不”class,如下所示。

"columnDefs": [ {
    /*"visible": false, <- this does not work with responsive*/
    "className": "never",
    "targets": 0,
    }]