问题描述
在使用DataTables的分页功能时,如何指定在单个页面上显示的行数?
How can I specify the number of rows to display on a single "page" when using DataTables's pagination feature?
推荐答案
对于DataTable 1.10.5和更新的,如,每页显示的行数可以通过源(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>
对于DataTable版本1.10和更新的,如,可以通过 pageLength $ c来指定每页显示的行数$ c>属性:
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 的DataTable,如,可以通过 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 make one dataTable call while providing the option to configure how each individual table behaves:
<table class="apply_dataTable" data-page-length='25'>
...
</table>
<table class="apply_dataTable" data-page-length='50' data-order='[[2, "desc"]]'>
...
</table>
<script>
$('table.apply_dataTable').dataTable(); //one invocation of datatables treats each table they way it wants to be
</script>
这篇关于更改要在一个“页面”上显示的默认行数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!