Reputation: 7040
HI all
I want to paginate with table i.e in one page have contain 5 data table, but i can not find the useful document in django template so now i want to implement it with jquery. sow how can i it implement???
Upvotes: 2
Views: 19032
Reputation: 292
you can use this function . Its taken from https://convertintowordpress.com/simple-jquery-table-pagination-code/
function pagination(){
var req_num_row=10;
var $tr=jQuery('tbody tr');
var total_num_row=$tr.length;
var num_pages=0;
if(total_num_row % req_num_row ==0){
num_pages=total_num_row / req_num_row;
}
if(total_num_row % req_num_row >=1){
num_pages=total_num_row / req_num_row;
num_pages++;
num_pages=Math.floor(num_pages++);
}
for(var i=1; i<=num_pages; i++){
jQuery('#pagination').append("<a href='#' class='btn'>"+i+"</a>");
}
$tr.each(function(i){
jQuery(this).hide();
if(i+1 <= req_num_row){
$tr.eq(i).show();
}
});
jQuery('#pagination a').click(function(e){
e.preventDefault();
$tr.hide();
var page=jQuery(this).text();
var temp=page-1;
var start=temp*req_num_row;
//alert(start);
for(var i=0; i< req_num_row; i++){
$tr.eq(start+i).show();
}
});
}
Upvotes: 0
Reputation: 40512
Here are some tutorials about applying pagination with jquery.
Complete script for sorting and paging
Complete tutorial on pagination with jquery
EDIT: the above links 404. Here are new tutorials:
Making jQuery Pagination System
Upvotes: 5