如何禁用数据表的自动排序?

问题描述 投票:0回答:4

我的数据表初始化脚本是

$('#table').DataTable();

我想禁用表格列的自动排序

jquery datatable datatables
4个回答
4
投票

好的,我找到了解决方案

只需在表中添加 data-order = ' '

<table class="table table-striped table-bordered " id="table"  data-order=''>

1
投票

将 aaSorting 选项设置为空数组。它将禁用初始排序,

"aaSorting": []

示例:

$('#you_table_id').DataTable({
    "aaSorting": []
});

aaSorting
数组应包含要排序的每列的数组,最初包含列的索引和方向字符串(
asc
desc
)。


0
投票

//更新版本

$('#table').dataTable( {
  "ordering": false
} );

// 对于旧版本

这是通过将

bSortable
设置为 false 来完成的

$('#table').dataTable({
"bSortable": false 
});

作者:aoColumnDefs

$('#table').dataTable( {
    "aoColumnDefs": [ 
        { "bSortable": false, "aTargets": [ 0 ] }
    ] } );

作者:aoColumns

$('#table').dataTable( {
    "aoColumns": [ 
        { "bSortable": false },
        null,
        null,
        null,
        null
    ] } );

0
投票

使用 Font Awesome 禁用自定义分页图标的自动排序

$("#table").dataTable({
    pagingType: "simple",
    ordering: true,
    autoWidth: true,
    language: {
        emptyTable: "No data available in table",
        paginate: {
            previous: '<i class="fa fa-chevron-left"></i>',
            next: '<i class="fa fa-chevron-right"></i>',
        },
        search: "",
        searchPlaceholder: "Search",
        info: "_START_ - _END_ of _TOTAL_",
        infoEmpty: "",
        infoFiltered: "",
    },
    order: [] // Add this to Disable the auto-sorting
});
© www.soinside.com 2019 - 2024. All rights reserved.