问题
I have a table with more the fifty records in it. I want to display them in pages of five records per page. My current approach uses jquery datatables, as shown below.
$(document).ready(function () {
var length = $('#data-datatable tbody tr').length;
$('#data-datatable').dataTable({
"bFilter": false,
"bLengthChange": false,
"iTotalDisplayRecords" : 5,
"iTotalRecords": length
});
});
This shows all fifty records in one page! How can I get the display I want please?
回答1:
My assumptions with your question:
- You have a html-table, that is being populated from the context having all 50 rows.
- Now you want to do pagination for those elements.
Here, I'm going to show some approaches:
- Think about Django Pagination . You context variable will do the pagination.
- Use Django-datatable-view . It directly works with jquery-datatable.
回答2:
Instead of these two lines:
"iTotalDisplayRecords" : 5,
"iTotalRecords": length
Try this one line instead:
"pageLength": 5,
More here: https://datatables.net/reference/option/pageLength
Also, in order to actually see the paging buttons, you'll need to add this:
"dom": '<"top">t<"bottom">p<"clear">',
来源:https://stackoverflow.com/questions/30665865/paging-data-tables-in-jquery