更改显示的 jquery 数据表默认行数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9279788/
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
Change jquery datatables default row count shown
提问by DeltaTango
By default, datatables has 4 sizes of records to show: 10,25,50,100.
默认情况下,数据表有 4 种大小的记录要显示:10、25、50、100。
A) Is there a way to change this? I tried editing the jquery file to change the array to [30,60,90,120] itself and this destroyed it.
A) 有没有办法改变这一点?我尝试编辑 jquery 文件以将数组更改为 [30,60,90,120] 本身,这破坏了它。
B) Is there a way to set the default selection size say to 50 (instead of 10) of this selector upon initializing when jquery builds it?
B) 有没有办法在 jquery 构建时在初始化时将此选择器的默认选择大小设置为 50(而不是 10)?
I can't find either of these items in the documentation.
我在文档中找不到这些项目中的任何一个。
回答by Greg Pettit
[Update because this answer seems to get some views] --
[更新,因为这个答案似乎得到了一些意见]-
Updated Answer:
更新答案:
In later versions (I believe 1.10+), the API naming conventions changed, ditching the Hungarian notation. I believe the old conventions are aliased for compatibility, but the current conventions are:
在更高版本(我相信 1.10+)中,API 命名约定发生了变化,抛弃了匈牙利表示法。我相信旧的约定是为了兼容性而别名的,但当前的约定是:
lengthMenu
pageLength
Thus, the updated answers are:
因此,更新的答案是:
A) it's the lengthMenuparameter: https://datatables.net/reference/option/lengthMenu
A)它的lengthMenu参数:https: //datatables.net/reference/option/lengthMenu
For example, here's how I have one of mine set:
例如,这是我如何拥有我的一套:
"lengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "All"]],
B) pageLength https://datatables.net/reference/option/pageLength-- optionally set this to whatever your default should be.
B) pageLength https://datatables.net/reference/option/pageLength- 可选择将其设置为您的默认值。
"pageLength" : 25,
Original Answer
原答案
A) It's the aLengthMenuparameter: http://datatables.net/ref#aLengthMenu
A)这是aLengthMenu参数:http: //datatables.net/ref#aLengthMenu
For example, here's how I have one of mine set:
例如,这是我如何拥有我的一套:
"aLengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "All"]],
B) iDisplayLength-- set this parameter to whatever your default should be
B) iDisplayLength-- 将此参数设置为您的默认值
回答by Gyrocode.com
DataTables 1.10+
Use
lengthMenuto define a list of available page lengths and optionallypageLengthto set initial page length.If
pageLengthis not specified, it will be automatically set to the first value given in array specified bylengthMenu.var table = $('#example').DataTable({ lengthMenu: [ [2, 4, 8, -1], [2, 4, 8, "All"] ], pageLength: 4 });See this jsFiddlefor code and demonstration.
数据表 1.10+
使用
lengthMenu定义可用的页面的长度,并且一个清单任选pageLength到组初始页长度。如果
pageLength未指定,它将自动设置为由指定的数组中给出的第一个值lengthMenu。var table = $('#example').DataTable({ lengthMenu: [ [2, 4, 8, -1], [2, 4, 8, "All"] ], pageLength: 4 });有关代码和演示,请参阅此 jsFiddle。
DataTables 1.9
Use
aLengthMenuto define a list of available page lengths andiDisplayLengthto set initial page length.var table = $('#example').dataTable({ "aLengthMenu": [ [2, 4, 8, -1], [2, 4, 8, "All"] ], "iDisplayLength" : 4, });See this jsFiddlefor code and demonstration.
数据表 1.9
使用
aLengthMenu定义可用页长的列表,并iDisplayLength设置初始页面长度。var table = $('#example').dataTable({ "aLengthMenu": [ [2, 4, 8, -1], [2, 4, 8, "All"] ], "iDisplayLength" : 4, });有关代码和演示,请参阅此 jsFiddle。
回答by Bal Krishan Dubey
Datatable Version : 1.9.4 What works for me is this:- First I searched the Jquery.dataTables file which is mostly placed in the js folder. Then I search for "aLengthMenu": [ 10, 25, 50, 100 ], and changed it according to my requirements i.e. "aLengthMenu": [ 50, 75, 100, 125 ]. Thereafter I searched for "iDisplayLength" and wherever its value is shown as 10 (4 to 5 places), I changed it to 50 and save. Dropdown on my index page started showing row option as 50,75,100,125 in place of 10,25,50,100 with default option selected as 50.
数据表版本:1.9.4 对我有用的是:- 首先,我搜索了主要放在 js 文件夹中的 Jquery.dataTables 文件。然后我搜索“aLengthMenu”:[ 10, 25, 50, 100 ],并根据我的要求进行更改,即“aLengthMenu”:[ 50, 75, 100, 125 ]。此后,我搜索了“iDisplayLength”,并将其值显示为 10(4 到 5 个位置),然后将其更改为 50 并保存。我的索引页上的下拉列表开始将行选项显示为 50,75,100,125 代替 10,25,50,100,默认选项选择为 50。

