我正在尝试禁用其中一列的排序功能。
我已经尝试过多种方法,但这些都不起作用。
我尝试添加:data-sorter="false"
给我的<th>
但它只是忽略了它。
我也尝试过这个,但它也只是忽略了它:
“columnDefs”: [ {
“targets”: 2,
“orderable”: false
}]
当我尝试这些方法时,我没有收到任何错误。
我还发现使用检查元素我的 <th>
自动获取类sorting
添加到其中。
这是我的代码:
我的 table :
<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
} ]
});
});
请帮助我,过去三天我一直在寻找答案。
最佳答案
您是否尝试设置"bSort":false
?欲了解更多详情,请参阅THIS
“bSort”:假
<小时/>
要禁用特定列的排序:
"bSortable": false
更具体:
$('#table').dataTable( {
"bSort":true,
aoColumnDefs: [
{ aTargets: [ '_all' ], bSortable: false },
{ aTargets: [ 0 ], bSortable: true },
{ aTargets: [ 1 ], bSortable: true }
]
}
关于javascript - 如何禁用数据表中列的排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52604022/