如何在jQuery datatable分页中显示所有页码?
例如,我需要1 2 3 ... 10
而不是1 2 3 4 5 6 7 8 9 10
。
我的代码现在是这样的:
$('.paginated-table').dataTable({
"lengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
"ordering": false,
"info": false,
"bFilter": false,
"sDom": "t<'row'<'col-md-12'p>>",
"oLanguage": {
"oPaginate": {
"sNext": "",
"sPrevious": "",
}
}
});
答案 0 :(得分:3)
计算页面按钮的逻辑是here:
var extPagination = DataTable.ext.pager;
function _numbers ( page, pages ) {
var
numbers = [],
buttons = extPagination.numbers_length,
half = Math.floor( buttons / 2 ),
i = 1;
if ( pages <= buttons ) {
numbers = _range( 0, pages );
}
...
numbers.DT_el = 'span';
return numbers;
}
因此,您可以将numbers_length
属性修改为更大的值(默认为7
),省略号将消失,显示所有页码:
$.fn.dataTableExt.pager.numbers_length = 600;
for (var i = 0; i < 500; ++i) {
$("tbody").append("<tr><td>" + i + "</td><td>" + Math.random() + "</td></tr>");
}
$.fn.dataTableExt.pager.numbers_length = 600;
$("table").dataTable({
ordering: false,
info: false,
bFilter: false,
extPagination: {
numbers_length: 600
}
});
a {
margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<table border="1">
<thead>
<tr>
<th>#</th>
<th>Random numbers</th>
</tr>
</thead>
<tbody>
</tbody>
</table>