数据表选项 pageLength/ lengthMenu 和 order 不起作用

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

我有一个表,我不想对其进行排序,并且我需要在页面上显示所有行。但由于某种原因,订单选项和 pageLength 都不起作用。表格继续按第一列排序,长度选项仍然是 5 - 10(默认选择)- 25 和 50。

这是我的代码:

var tableReport = $('#table-report-report').DataTable();
        new $.fn.dataTable.Buttons(tableReport, {
            order: [],
            pageLength: 100,
            lengthMenu: [ [100], ["All"] ],
            buttons: [
                'pageLength',
                {
                    extend:    'excelHtml5',
                    text:      '<i class="fa fa-file-excel-o"></i>',
                    titleAttr: 'Excel'
                }
            ]
        }).container().appendTo($('#buttons-report-report'));

我尝试根据 documentary 更改它,就像在 pageLength 示例中所做的那样,但它仍然不起作用。我尝试了这段代码:

var tableReport = $('#table-report-report').DataTable();
            new $.fn.dataTable.Buttons(tableReport, {
                dom: 'Bfrtip',
                lengthMenu: [
                    [ 10, 25, 50, -1 ],
                    [ '10 rows', '25 rows', '50 rows', 'Show all' ]
                ],
                buttons: [
                    'pageLength'
                ]
            }).container().appendTo($('#buttons-report-report'));

使用此代码,它仍然为我提供相同的 5-10(默认选择)- 25 - 50 个选项。

我不想订餐桌。但即使我要求不要使用 order : [] 来排序,它仍然按第一列值排序。我也尝试过 order : false,不会改变任何东西。

我不知道如何解决这个问题,请问有人可以帮助我吗? Excel 导出按钮工作正常。

jquery datatable
1个回答
0
投票
尝试这样

$(document).ready(function() { $('#table-report-report').DataTable( { "ordering": false, lengthMenu: [ [ 10, 25, 50, -1 ], [ '10 rows', '25 rows', '50 rows', 'Show all' ] ], buttons: [ 'pageLength' ] } ); } );

https://codepen.io/abisha__25/pen/KKbENbY

© www.soinside.com 2019 - 2024. All rights reserved.