Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

twbs-pagination Start page option is incorrect

I need some help. I get error when my page count is 0 "Start page option is incorrect"

here is my code

$rows = $employee->countData($param);
$per_page = 5;
$pages = ceil( $rows / $per_page );

the value of $pages is 0

This is how I get the pages by using jquery.ajax

var total_pages = data;
var logid = '30';

$('#pagination')
  .empty()
  .removeData("twbs-pagination")
  .unbind("page");

$('#pagination').twbsPagination({

  totalPages: total_pages,
  visiblePages: 7,
  onPageClick: function (event, page) {
      $('#container').load('load_data.php',{page:page,id:logid});
  }
});

$('#container').load('load_data.php',{id:logid});

here is my load_data.php

$page = isset($_POST['page']) ? (int) $_POST['page'] : 1 ;

$id = $_POST['id'];

$per_page = 5;

if($page == 0)
    $start = 0;
else
    $start = ( $page - 1 ) * $per_page;


$result = $emp->getPainateData($id,$start,$per_page);

Thank you in advance.

like image 303
jemz Avatar asked Jul 08 '15 09:07

jemz


2 Answers

I've solved a similar issue base on this solution. Basically you just need to check the element for twbsPagination, and if it exists destroy it.

var total_pages = data;
var logid = '30';

if($('#pagination').data("twbs-pagination"))
  $('#pagination').twbsPagination('destroy');


$('#pagination').twbsPagination({
  totalPages: total_pages,
  visiblePages: 7,
  onPageClick: function (event, page) {
      $('#container').load('load_data.php',{page:page,id:logid});
  }
});

$('#container').load('load_data.php',{id:logid});
like image 58
Shiran Dror Avatar answered Nov 04 '22 19:11

Shiran Dror


JQuery TwbsPagination will return this error if below condition became true:
this.options.startPage < 1 || this.options.startPage > this.options.totalPages
So as you said 'my page count is 0' this condition will always be true, so you always will see this error. (startpage option does not matter)
I hope this helps.

like image 32
Pouria Moosavi Avatar answered Nov 04 '22 21:11

Pouria Moosavi