假设我有如下表格:
我想禁用操作列
的排序
<!--index.html-->
<table class="table table-striped table-bordered post-list-table" id="table" >
<thead>
<tr>
<th>Title</th>
<th>Created At</th>
<th>Action</th>
</tr>
</thead>
</table>
<!--Script.js-->
$('#table').DataTable();
答案 0 :(得分:12)
尝试添加: columns.orderable
"columnDefs": [
{ "orderable": false, "targets": 2 }
]
<!--Script.js-->
$('#table').DataTable( {
"columnDefs": [
{ "orderable": false, "targets": 2 }
]
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet"/>
<table class="table table-striped table-bordered post-list-table" id="table" >
<thead>
<tr>
<th>Title</th>
<th>Created At</th>
<th>Action</th>
</tr>
</thead>
</table>
答案 1 :(得分:2)
试试这个
$('#table').dataTable({
// display everything
"iDisplayLength": -1,
"aoColumns":[
{"bSortable": true},
{"bSortable": true},
{"bSortable": false}
]
});
答案 2 :(得分:1)
将一个类添加到要禁用排序的列中
<th class="no-sort">Operations</th>
然后在您的CSS中添加以下样式
table.datatable thead th.no-sort {
background: none;
pointer-events: none;
}
答案 3 :(得分:1)
在jQuery中执行
var table = $('#tbl').DataTable({
"columnDefs": [{ targets: 'no-sort', orderable: false }]});
并向您要禁用此类排序的所有标头添加“ no-sort”类。
<th class="no-sort">Header n</th>
答案 4 :(得分:0)
如果你想禁用所有列的排序,那么你可以在footable中执行$(th).unbind();