TwbsPagination totalPage value always changing?

 $('#pagination').twbsPagination({
                totalPages: "5",
                visiblePages: "5",
                onPageClick: function (event, page) {
}

I have a list that can be filtered by 10, 100 and 1000. If there are 12 documents in the database and the user uses filter 10, the total will be essentially 2: 10 on the first page and 2 documents on the second page.

+4
source share
1 answer

It depends on how you retrieve the information. In the case of an AJAX call, you can do this after receiving the result:

  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 in this event onPageClick: function (event, page) {}you should assign the next ajax call and if the provided code is successfully placed. Something like that.

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

. , .

+2

Source: https://habr.com/ru/post/1678730/


All Articles