GhitaB
GhitaB

Reputation: 3437

How to show all page numbers in jQuery DataTable pagination

How to show all page numbers in jQuery datatable pagination? For example instead of 1 2 3 ... 10, I want 1 2 3 4 5 6 7 8 9 10.

My code now is this:

$('.paginated-table').dataTable({
  "lengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
  "ordering": false,
  "info":     false,
  "bFilter": false,
  "sDom": "t<'row'<'col-md-12'p>>",
  "oLanguage": {
    "oPaginate": {
      "sNext": "",
      "sPrevious": "",
    }
  }
});

Upvotes: 5

Views: 6186

Answers (1)

Ionică Bizău
Ionică Bizău

Reputation: 113465

The logic for computing the page buttons is here:

var extPagination = DataTable.ext.pager;

function _numbers ( page, pages ) {
    var
        numbers = [],
        buttons = extPagination.numbers_length,
        half = Math.floor( buttons / 2 ),
        i = 1;

    if ( pages <= buttons ) {
        numbers = _range( 0, pages );
    }
    ...

    numbers.DT_el = 'span';
    return numbers;
}

So, you can modify the numbers_length property to a bigger value (default is 7) and the ellipses will dissapear, all the page numbers being displayed:

$.fn.dataTableExt.pager.numbers_length = 600;

for (var i = 0; i < 500; ++i) {
  $("tbody").append("<tr><td>" + i + "</td><td>" + Math.random() + "</td></tr>");
}

$.fn.dataTableExt.pager.numbers_length = 600;

$("table").dataTable({
  ordering: false,
  info: false,
  bFilter: false,
  extPagination: {
    numbers_length: 600
  }
});
a {
  margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<table border="1">
  <thead>
    <tr>
      <th>#</th>
      <th>Random numbers</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>

Upvotes: 5

Related Questions