I'm trying to use jqPagination to paginate products which can be filtered using ajax. All works fine until this: let's say I have 20 products, 5 products per page, meaning 4 pages. Now, my issue comes up if I filter the products and get (ie) 2 pages only and I was on page 4 when I was applying the filter. The jqPagination input says Page 4 of 4. (if I were on page 1 or 2 when I was applying the ajax filter works fine). Here's the jquery code I use:
$(document).ready(function() {
var records_per_page = 5;
var records = $('#products div.productItem').length;
var pages = Math.ceil(records/records_per_page);
$('#products div.productItem').slice(records_per_page).hide();
$('.pagination').jqPagination({
max_page : pages,
page_string : '{current_page} of {max_page}',
paged : function(page) {
var start_rec = records_per_page * (page-1);
var stop_rec = start_rec+records_per_page;
$('#products div.productItem').hide();
$('#products div.productItem').slice(start_rec,stop_rec).show();
}
});
});
$.ajax({
url: "modules/modules/_ajax-filters.php",
data: { marke: selBrandStr, lieferung: selDeliveryStr, minPrice: minPriceFilter, maxPrice: maxPriceFilter, pag: pag },
type:"post",
async: false,
cache: false,
dataType: "html",
success: function (html) {
$('#products').html('');
$('#products').html(html);
var records_per_page = 5;
var records = $('#products div.productItem').length;
var pages = Math.ceil(records/records_per_page);
$('.pagination').jqPagination('option', 'max_page', pages);
$('.pagination').jqPagination('option', 'current_page', 1);
}
});
I found myself the answer... I had to change between them the lines
$('.pagination').jqPagination('option', 'max_page', pages);
$('.pagination').jqPagination('option', 'current_page', 1);
and become:
$('.pagination').jqPagination('option', 'current_page', 1);
$('.pagination').jqPagination('option', 'max_page', pages);
and now works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.