简体   繁体   English

如何防止对特定表列进行排序 - DataTable?

[英]How to prevent sorting on specific table column - DataTable?

I don't want to sort my action column, so I did :我不想对我的操作列进行排序,所以我做了:

<th class="no-sort" >Actions</th>

and update my JS like this并像这样更新我的 JS

$('table').DataTable( {
    "bLengthChange": true,
    "Filter": true,
    "Info": true,
    "bSort": true,
    "bPaginate": false,
    "searchHighlight": true,
    "aoColumnDefs": [{
        "bSort": false,
        "aTargets": ["no-sort"]
    }]
} );

I still see that it is sortable.我仍然看到它是可排序的。 🤦🏻‍♂️ 🤦🏻‍♂️

在此处输入图片说明

How do I stop that ?我该如何阻止?

The correct property is bSortable , not bSort .正确的属性是bSortable ,而不是bSort See the documentation查看文档

"aoColumnDefs": [{
  "bSortable": false,
  "aTargets": ["no-sort"]
}]

Also note that from your use of aoColumnDefs it appears you're using a very old version of DataTables;另请注意,从您使用aoColumnDefs看来,您使用的是非常旧版本的 DataTables; at least 5 years old in fact.事实上至少5岁。 I'd suggest upgrading it when possible.我建议在可能的情况下升级它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM