问题描述
在使用 DataTables 的分页功能时,如何指定要在单个页面"上显示的行数?
How can I specify the number of rows to display on a single "page" when using DataTables's pagination feature?
推荐答案
对于 DataTables 1.10.5 和更新版本,如 博客文章宣布集成 HTML5 data-* 属性,可以通过源指定每页显示的行数(HTML) 表格通过 data-page-length
属性:
For DataTables version 1.10.5 and newer, as documented on the blog post announcing the integration of HTML5 data-* attributes, the number of rows to show per page can be specified via the source (HTML) table through the data-page-length
attribute:
<table data-page-length='25'>
...
</table>
对于 DataTables 1.10 及更新版本,如参考 > 选项 > pageLength 所述,每页显示的行数可以通过 pageLength
属性指定:
For DataTables version 1.10 and newer, as documented at Reference > Options > pageLength, the number of rows to show per page can be specified via the pageLength
attribute:
$('#example').dataTable( {
"pageLength": 50
});
对于 1.10 版之前的 DataTables,如DataTables > Usage 所述> Options > iDisplayLength,可以通过iDisplayLength
属性指定每页显示的行数:
For DataTables older than version 1.10, as documented at DataTables > Usage > Options > iDisplayLength, the number of rows to show per page can be specified via the iDisplayLength
attribute:
$('#example').dataTable( {
"iDisplayLength": 50
});
我的两分钱:使用 data-*
方法.它允许您构建一个 dataTable 调用(您可以在整个应用程序中使用),同时提供配置每个单独表行为方式的选项:
My two cents: use the data-*
approach. It allows you to construct one dataTable call (that you can use throughout your app) while providing the option to configure how each individual table behaves:
<!-- table with embedded custom configurations -->
<table class="apply_dataTable" data-page-length='25'>
...
</table>
<!-- table with different embedded custom configurations -->
<table class="apply_dataTable" data-page-length='50' data-order='[[2, "desc"]]'>
...
</table>
<!-- one JavaScript call enhances both tables above -->
<script>
$('table.apply_dataTable').dataTable(); //one invocation of datatables treats each table they way it wants to be
</script>
这篇关于更改要在一页“上"显示的默认行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!