jquery - DataTables 将排序图标放在指定为没有的列上

标签 jquery html css datatables

数据表 1.10.18

我已经按如下方式定义了我的表的列:

columns: [
          { "data": "expand_link", "name": "expand_link" },
          { "data": "date", "name": "date" },
          { "data": "col1", "name": "col1" },
          { "data": "col2", "name": "col2" },
          { "data": "col3", "name": "col3" },
        ],
        "columnDefs": [
            {"width": "5%", "targets": 0},
            {"width": "12%", "targets": 1},
            {"width": "35%", "targets": 2},
            {"width": "35%", "targets": 3},
            {"width": "12%", "targets": 4},
            {"orderable": false, "targets": [0, 2, 3, 4]} // Can order by Date only
        ],

{"orderable": false, "targets": [0, 2, 3, 4]} 意味着不可能对第 0、2、3 和 4 列进行排序. 这意味着第 1 列是可订购的。

但是当呈现表格时,它会将向上/向下箭头图标放在第 0 列和第 1 列上:

enter image description here

其他列(col1...col3,索引 2 - 4)没问题,因为它们不包含预期的排序图标:

enter image description here

为什么它在 js 中指定后对第 0 列 (expand_link) 不起作用?

最佳答案

https://datatables.net/reference/option/columns.orderable#Comments 有用户评论说到这里,

Note that in both examples given, a (disabled) sort control will still appear on column 0 unless you specify a default order on a different column using order.

https://datatables.net/forums/discussion/21709/orderable-false-on-target-0-first-col-not-working-until-another-column-is-sorted更详细地解释问题和修复:

After some more research, it looks like this is actually intended behavior because the table is by default sorted on the first column. So the indicator is there to show you that the table is sorted on that column. In order to remove the indicator, you need to tell the table to default sort on a different column, or no column at all.

关于jquery - DataTables 将排序图标放在指定为没有的列上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57902737/

相关文章:

javascript - Bootstrap 日期时间选择器日历未显示

用于在 HTML 表格或 div 网格中将列转换为行以及将行转换为列的 JavaScript 代码或框架

javascript - 第一项的旋转木马填充

javascript - 在 Vue 中使用 Web 组件

java - XSS 和 Applet/Param HTML 关键字

html - 当父 div 定位为相对且子 div 定位为绝对时,元素变得不可见

javascript - 如何在每个 html 页面上单独执行 jQuery/Ajax 加载

javascript - 如果我有两个 Canvas 相互重叠,是否可以实现 html canvas 复合操作 "lighter"?

css - Bootstrap : Mobile specific changes how?

html - 如何将一组动画 div 的起点垂直居中