假设我有如下表格:
我想禁用Action Column的排序
<!--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();
Run Code Online (Sandbox Code Playgroud)
Ana*_*nda 19
尝试添加: columns.orderable
"columnDefs": [
{ "orderable": false, "targets": 2 }
]
Run Code Online (Sandbox Code Playgroud)
<!--Script.js-->
$('#table').DataTable( {
"columnDefs": [
{ "orderable": false, "targets": 2 }
]
});Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
小智 6
在 jQuery 中执行此操作
var table = $('#tbl').DataTable({
"columnDefs": [{ targets: 'no-sort', orderable: false }]});
Run Code Online (Sandbox Code Playgroud)
并向您要禁用排序的任何标题添加一个类“无排序”。
<th class="no-sort">Header n</th>
Run Code Online (Sandbox Code Playgroud)