在排序时使用false选项对DataTables进行排序 [英] sorting DataTables with setting false option on ordering
问题描述
是否可以通过禁用更改排序按第二列设置默认排序表?
Is it possible setting default sorting table by second column with disable change sorting?
我以这种方式尝试,但是在第二列的标题上可以看到一个箭头. 我想用默认排序删除所有箭头.
I try in this way but on header of second column an arrow is visible. I want remove all arrow with the default sorting.
var table = data.DataTable({
"pageLength": 5,
"lengthChange": false,
"info" : false,
"responsive": true,
"ordering": true,
"order": [ 1, "asc" ],
"columnDefs": [{
"targets": "_all", "orderable": false
}],
"data": result,
"columns": [
{ "data": null },
{ "data": "Class" },
{ "data": "count" },
{ "data": "group" }
]
});
table.on('order.dt', function () {
table.column(0, { search: 'applied', order: 'applied' }).nodes()
.each(function (cell, i) {
cell.innerHTML = i + 1;
});
}).draw();
推荐答案
您可以使用以下jQuery命令从元素中删除灰色三角形(背景图片):
You can use this jQuery command to remove the grey triangle (background image) from the element:
$("th.sorting_desc").css('background-image', 'none');
这需要放在文档准备就绪"部分的末尾(假设这就是您正在做的事情).
This needs to be placed at the end of the "document ready" section (assuming that is what you are doing).
我唯一要添加的是:三角形存在是有原因的-告诉用户如何对数据进行排序.我不愿意自己删除它(只是我的意见).
The only thing I would add is this: The triangle is there for a reason - to tell users how the data is sorted. I'd be reluctant to remove it myself (just my opinion).
(您的"targets": "_all", "orderable": false
已经解决了排序问题.该表一旦显示就不能被用户排序.)
(Your "targets": "_all", "orderable": false
has taken care of the sorting question already. The table is not sortable by the user, once it has been displayed.)
更新
当您将鼠标悬停在表格标题上时,您可能还希望停止更改光标(出于UI体验的一致性):
You may also want to stop the cursor from changing, when you roll over the table heading (for consistency of UI experience):
$("th.sorting_desc").css('cursor', 'default');
(仅在Firefox和Chrome中测试.)
(Tested only in Firefox and Chrome.)
这篇关于在排序时使用false选项对DataTables进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!