繁体   English   中英

如何禁用对数据表中的列进行排序

[英]How to disable sorting on a column in a datatable

我试图在我的其中一列上禁用排序功能。
我已经尝试了多种方法,但是这些方法没有用。
我尝试在我的<th>添加以下内容: data-sorter="false" ,但它只是忽略了它。
我也尝试过,但也忽略了它:

“columnDefs”: [ {
“targets”: 2,
“orderable”: false
}]

当我尝试这些方法时,我没有得到任何错误。 我还发现使用inspect元素,我的<th>自动将添加的类sorting添加到其中。
这是我的代码:
我的桌子:

<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
 <thead>
        <tr>
            <th>Vraag</th>
            <th>Gepost op</th>
            <th>Acties</th>// I want to disable sorting here
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

我的js:

// Call the dataTables jQuery plugin
$(document).ready(function() {
  $('#dataTable').DataTable({
    "columnDefs": [ {
      "targets": 2,
      "orderable": false
    } ]
  });
});

请帮助我,我一直在寻找最近3天的答案。

您是否尝试设置"bSort":false 欲了解更多详情,请参阅


禁用从数据表排序

"bSort":false


要禁用对特定列的排序:

"bSortable": false


更加具体:

  $('#table').dataTable( { "bSort":true, aoColumnDefs: [ { aTargets: [ '_all' ], bSortable: false }, { aTargets: [ 0 ], bSortable: true }, { aTargets: [ 1 ], bSortable: true } ] } 

暂无
暂无

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

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