我正在使用Jquery数据表,我需要对一列进行排序图标和排序/搜索false
这是我的代码
$(document).ready(function () {
$('#tblUsers').DataTable({
"searching": true,
"ordering": true,
"pagingType": "full_numbers",
"ajax": "GetUsers",
"columnDefs": [{
"targets": 0,
"data": "Id",
"orderable": false,
"searchable": false,
"render": function (data, type, full, meta) {
return '<a href="MangeUser/' + data + '">Edit User</a>';
}
}],
"columns": [
{
"data": "Id"
},
{ "data": "FirstName" },
{ "data": "LastName" },
{ "data": "UserName" },
{ "data": "RoleName" }
]
});
});
和html如下
<table id="tblUsers" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th>FirstName</th>
<th>LastName</th>
<th>Email Id</th>
<th>RoleName</th>
</tr>
</thead>
</table>
现在即使设置了orderable / searchable为false,它仍会在第一次加载页面时显示,但是当我点击其他地方时,图标就消失了
答案 0 :(得分:1)
只需将数据表选项中的顺序添加到空数组,就像这样
order: []
因为默认情况下它会应用第0列的顺序,因此即使我们使其不可排序,它也会显示排序图标。通过设置此属性,您将覆盖此行为
$('#tblUsers').DataTable({
"order" : [], // this new option
"searching": true,
"ordering": true,
"pagingType": "full_numbers",
...