jQuery DataTables 分页大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8051302/
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
jQuery DataTables Pagination Size
提问by Sam
i've been using jQuery DataTables plugin ( http://datatables.net) for quite some time and usually we're super fine using the default sizes and using "bStateSave": true
option.
我已经使用 jQuery DataTables 插件(http://datatables.net)有一段时间了,通常我们使用默认大小和使用"bStateSave": true
选项非常好。
But now i really need to set the sizing of the pagination not as [10,25,50,100] but rather i need this as let's say [1,2,3]. I get the menu to set like this with setting the option aLengthMenu:[1,2,3]
and if i select one of the options it sets the correct selection amount.
但是现在我真的需要将分页的大小设置为 [10,25,50,100] 而不是我需要这个,比如 [1,2,3]。我通过设置选项来设置菜单aLengthMenu:[1,2,3]
,如果我选择其中一个选项,它会设置正确的选择量。
But on dataTable STARTUP it doesn't set the length to 1,2,3 but rather to the default '10'
但是在 dataTable STARTUP 上,它没有将长度设置为 1,2,3,而是设置为默认的“10”
Which option am i missing? Thanks in advance!
我缺少哪个选项?提前致谢!
采纳答案by Gyrocode.com
DataTables 1.10+
Use
lengthMenu
to define a list of available page lengths and optionallypageLength
to set initial page length.If
pageLength
is 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
aLengthMenu
to define a list of available page lengths andiDisplayLength
to 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 max4ever
clear your cookies, the ones datatables saved when you were using bStateSave and you had 10,25,50,100
清除您的 cookie,即您使用 bStateSave 时保存的数据表,并且您有 10,25,50,100
then refresh and it should now save 1 or 2 or 3
然后刷新,它现在应该保存 1 或 2 或 3
do you mean
你的意思是
"aLengthMenu": [[5, 10, 15, 25, 50, 100 , -1], [5, 10, 15, 25, 50, 100, "All"]],
"iDisplayLength" : 10,
回答by user3444748
Make sure to wait, until you angular things load.
确保等待,直到有角度的东西加载。
$timeout(function(){ // given timeout for wait load the page
$('#dataTables-example').dataTable({
"iDisplayLength": 10,
});
}, 100, false);