Pagination: How to control number of pages either side of active

Pagination: How to control number of pages either side of active

ButchNZButchNZ Posts: 20Questions: 6Answers: 0
edited June 24 in DataTables 2

How can I change the pagination number either side of active?

By default I have:

Ideally I'd like that to be:

<< < 1 2 3 4 5 6 7 > >>

Where the current page is 4.
Said in words, 3 either side of current when you can.
Never show first/last page as a page link unless it's part of the 7 page sequence (there's << >> buttons for that).

I saw I can use:

$.fn.DataTable.ext.pager.numbers_length = 6;

To change number of pages but didn't quite do the above.

I read this page in the examples but doesn't seem possible there.
https://datatables.net/examples/basic_init/alt_pagination.html

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,488Questions: 1Answers: 10,468 Site admin

    I think the paging.boundaryNumbers option is what you are looking for here. It will still show the ellipsis to indicate a gap, but you could use CSS to hide those elements if you so wished to do so.

    Allan

  • ButchNZButchNZ Posts: 20Questions: 6Answers: 0

    I've added it like this with no change.

    datatable = thetable.DataTable(
    {
        ......
        processing: true,
        layout: {
            bottomEnd: {
                paging: {
                    boundaryNumbers: false
                }
            }
        },
        columns: [...]
        ......
    }
    

    Did I do it wrong or maybe DOM templates changed?

    My DOM template is:

    var defaultTemplate =
    '<"container-fluid px-3"<"row table-header justify-content-between py-3"' +
        '<"col-12 col-md-5 d-flex align-items-center mb-3 mb-md-0"lB>' + // Page size and buttons
        '<"col-12 col-md-5 col-lg-4 d-flex justify-content-end align-items-center"f>' +      // Search box
    '>>t' +
    '<"container-fluid p-3"<"row align-items-center"' +
        '<"col-sm-12 col-md-6 mb-3 mb-md-0"i>' + // paging stats
        '<"col-sm-12 col-md-6 d-flex justify-content-center justify-content-md-end"p>' + // paging
    '>>';
    
  • allanallan Posts: 63,488Questions: 1Answers: 10,468 Site admin
    Answer ✓

    You can't use dom and layout at the same time. boundaryNumber can only be done through the layout option. Also, the boundaryNumber feature requires DataTables 2.0.4 or newer.

    I'm working on updates for DataTables 2.1 at the moment that will give the same flexibility as dom currently does for setting class names and the like. At the moment, what you have cannot be exactly reproduced with layout, but 2.1 will make that possible.

    Allan

  • ButchNZButchNZ Posts: 20Questions: 6Answers: 0

    Cool no problem. Thanks!

Sign In or Register to comment.