2017-06-07 52 views
4
$('#pagination').twbsPagination({ 
       totalPages: "5", 
       visiblePages: "5", 
       onPageClick: function (event, page) { 
} 

我有一個可以按10,100和1000過濾的列表。如果數據庫有12個文檔,並且用戶使用10個過濾器,則totalPages在第一頁上基本上是2:10,而2個文檔在第二頁上。twbsPagination totalPage值總是在變化?

回答

2

這取決於你如何檢索信息。對onPageClick: function (event, page) {}事件

var $pagination = $('#pagination'); 
    var totalValue = 25; //for example 
    var toShow = 20; //show 20 items 
    var numOfPage = Math.ceil(totalValue/toShow); 
    if (numOfPage > 1) { 
     var totalPages = numOfPage; 
     var currentPage = $pagination.twbsPagination('getCurrentPage'); 
     $pagination.twbsPagination('destroy'); 
     $pagination.twbsPagination($.extend({}, defaultOpts, { 
       startPage: currentPage, 
       totalPages: totalPages 
     })); 
    } else { 
     $pagination.twbsPagination('destroy'); //don't show pagination 
              //if all item on the 1st page 
    } 

UPDATE應先分配下一個Ajax調用,併成功投放提供的代碼:在的情況下,AJAX,叫你能做到這樣,receving結果之後。像這樣的東西。

onPageClick: function (event, page) { 
     loadNextValues(page); //function to retrieve information. 
     //most probably you need this assignment -> page = page -/+ 1 
     //I don't remember exactly 
    } 

這個分頁是懶加載。至少提供算法。