jQuery 更改jquery数据表“显示10个条目”的选择框的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10630853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 09:36:43  来源:igfitidea点击:

Change values of select box of "show 10 entries" of jquery datatable

jquerydatatables

提问by rjmcb

By default, jquery datatable shows 10 by default and has

默认情况下,jquery 数据表默认显示 10 并且有

options : 10,25,50,100

选项 : 10,25,50,100

How can I change these options?

如何更改这些选项?

回答by davesave

Don't forget to change the iDisplayLength as well:

不要忘记更改 iDisplayLength:

$(document).ready(function() {
    $('#tbl_id').dataTable({
        "aLengthMenu": [[25, 50, 75, -1], [25, 50, 75, "All"]],
        "iDisplayLength": 25
    });
} );

回答by Priyank Patel

$(document).ready(function() {
    $('#example').dataTable( {
    "aLengthMenu": [[25, 50, 75, -1], [25, 50, 75, "All"]],
    "pageLength": 25
    } );
} );

aLengthMenu : This parameter allows you to readily specify the entries in the length drop down menu that DataTables shows when pagination is enabled. It can be either a 1D array of options which will be used for both the displayed option and the value, or a 2D array which will use the array in the first position as the value, and the array in the second position as the displayed options (useful for language strings such as 'All').

aLengthMenu :此参数允许您轻松指定启用分页时 DataTables 显示的长度下拉菜单中的条目。它可以是用于显示选项和值的一维选项数组,也可以是将第一个位置的数组用作值,将第二个位置的数组用作显示选项的二维数组(对于诸如“All”之类的语言字符串很有用)。

Update

更新

Since DataTables v1.10, the options you are looking for are pageLengthand lengthMenu

从 DataTables v1.10 开始,您正在寻找的选项是pageLengthlengthMenu

回答by Mira Padalia

In my case , aLengthMenuis not working. So i used this. And it is working.

就我而言,aLengthMenu不起作用。所以我用了这个。它正在发挥作用。

jQuery('#dyntable3').dataTable({            
            oLanguage: {sLengthMenu: "<select>"+
            "<option value='100'>100</option>"+
            "<option value='200'>200</option>"+
            "<option value='300'>300</option>"+
            "<option value='-1'>All</option>"+
            "</select>"},
            "iDisplayLength": 100

        });

Thank you

谢谢

回答by MZaragoza

According to datatables.netthe proper way to do this is adding the lengthMenu property with an array of values.

根据datatables.net,正确的方法是添加具有值数组的 lengthMenu 属性。

$(document).ready(function() {
    $('#example').dataTable( {
        "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
    } );
} );

回答by user3789888

 $('#tblSub1View').dataTable({
                    "bJQueryUI": true,
                    "sPaginationType": "full_numbers",
                    "bDestroy": true,
                    "aoColumnDefs": [{
                        'bSortable': false,
                        'aTargets': [0, 1]
                    }],
                    "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
                    "iDisplayLength": 10,
                });

回答by nihaoqiulinhe

if you click some button,then change the datatables the displaylenght,you can try this :

如果你点击某个按钮,然后改变数据表的显示长度,你可以试试这个:

 $('.something').click( function () {
var oSettings = oTable.fnSettings();
oSettings._iDisplayLength = 50;
oTable.fnDraw();
});

oTable = $('#example').dataTable();

回答by Kirill A

If you want to use 'lengthMenu' together with buttons(copy, export), you have to use this option dom: 'lBfrtip'. Here https://datatables.net/reference/option/domyou can find meaning of each symbol. For example, if you will use like this 'Bfrtip', lengthMenu will not appears.

如果您想将 'lengthMenu' 与按钮(复制、导出)一起使用,您必须使用此选项 dom: 'lBfrtip'。在这里https://datatables.net/reference/option/dom您可以找到每个符号的含义。例如,如果您像这样使用“Bfrtip”,则不会出现 lengthMenu。

回答by Sodruldeen Mustapha

you can achieve this easily without writing Js. Just add an attribute called data-page-length={put your number here}. see example below, I used 100 for example

您可以轻松实现这一点,而无需编写 Js。只需添加一个名为 data-page-length={put your number here} 的属性。请参见下面的示例,例如我使用了 100

<table id="datatable-keytable" data-page-length='100' class="p-table table table-bordered" width="100%">

回答by subramanya46

enter image description herepageLength: 50,

在此处输入图片说明页长:50,

worked for me Thanks

为我工作谢谢

Versions for reference

参考版本

jquery-3.3.1.js

jquery-3.3.1.js

/1.10.19/js/jquery.dataTables.min.js

/1.10.19/js/jquery.dataTables.min.js

/buttons/1.5.2/js/dataTables.buttons.min.js

/buttons/1.5.2/js/dataTables.buttons.min.js