我使用jQuery datatables插件对表字段进行排序.我的问题是如何禁用特定列的排序?我尝试使用以下代码,但它不起作用:
"aoColumns": [
{ "bSearchable": false },
null
]
Run Code Online (Sandbox Code Playgroud)
我也尝试了以下代码:
"aoColumnDefs": [
{
"bSearchable": false,
"aTargets": [ 1 ]
}
]
Run Code Online (Sandbox Code Playgroud)
但这仍然没有产生预期的结果.
假设我有如下表格:
我想禁用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) 我对dataTable真的很陌生,我只需要一个简单的解决方案:
var initBasicTable = function() {
var table = $('#basicTable');
var settings = {
"sDom": "t",
"sPaginationType": "bootstrap",
"destroy": true,
"paging": false,
"scrollCollapse": true,
"order": [[0,'desc']]
};
table.dataTable(settings);
$('#basicTable input[type=checkbox]').click(function() {
if ($(this).is(':checked')) {
$(this).closest('tr').addClass('selected');
} else {
$(this).closest('tr').removeClass('selected');
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是有效的,默认情况下对第一列进行排序.
但我读到将0in 更改"order": [[0,'desc']]为负数将从右侧的列开始排序.不过这个:
var settings = {
"sDom": "t",
"sPaginationType": "bootstrap",
"destroy": true,
"paging": false,
"scrollCollapse": true,
"order": [[-1,'desc']]
};
Run Code Online (Sandbox Code Playgroud)
抛出错误,我不知道从哪里继续.
我知道dataTable非常强大,但是, 这不是我想要的,但已经很多了
'按上一个(-1)列排序'没什么?我感到迷茫.任何人?