【问题标题】:How to disable sorting on a column in a datatable如何禁用对数据表中的列进行排序
【发布时间】:2019-03-07 07:48:40
【问题描述】:

我正在尝试禁用我的某一列的排序功能。
我已经尝试了多种方法,但这些都不起作用。
我尝试将这个:data-sorter="false" 添加到我的<th>,但它只是忽略了它。
我也试过这个,但它也忽略了它:

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

当我尝试这些方法时,我没有收到任何错误。 我还发现使用检查元素,我的<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 天我一直在寻找答案。

【问题讨论】:

    标签: javascript jquery html-table datatable


    【解决方案1】:

    您是否尝试设置"bSort":false?更多详情见THIS


    禁用从数据表排序

    "bSort":false

    禁用对特定列的排序:

    "bSortable": false


    更具体:

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

    【讨论】:

    • 这个工作除了我的第二列现在也禁用了排序prnt.sc/l15qaw
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-01
    • 2012-06-07
    • 2012-04-15
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多