displayStart works but results in incorrect page 'selected' button bottom right

displayStart works but results in incorrect page 'selected' button bottom right

blabablabablabablaba Posts: 47Questions: 19Answers: 0

I am using displayStart to show records starting from 13 from a table with 32 records.

Table displays the default 10 records per page.

The resultant table displays from record 13!

However... the default paging buttons (bottom right) reads 3. I would expect this to be 2.

As an extra test, I tried table.page.info().page reads correctly '1' (counting from 0, is what I expect). Why is th paging button on 3? Is this a bug?

Is the value denoting the 'selected' page derived from the upper bound of the rows starting from 13 (13+10=23), which might explain the anomaly, in which case it would be a bug.

What do you think?

Sample code below.

$('#example').DataTable({

    dom: "Bfrtip",
    ajax: {

// Working Ajax
},
displayStart: 13, // Display from Row
order: [[ 1, 'asc' ]],
columns: [
{
data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false
},
// some other columns

    ],
    select: {
        style:    'os',
        selector: 'td:first-child'
    },
    buttons: [
            {
                text: 'info',
                action: function( e, dt, node, config ){

console.log(table.page.info());
console.log('the page we want to return to is: '+table.page.info().page);
}
},
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]

});

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,241Questions: 1Answers: 10,210 Site admin
    Answer ✓

    It does sound like it might be a bug, but then I'm not sure that any of the DataTables logic was built for having an offset in the pagination like that. If the page length is 10 and you start at record 13, that's really page 2.3.

    Can you set the page length to be 13 (pageLength) that would resolve the issue.

    Allan

  • blabablabablabablaba Posts: 47Questions: 19Answers: 0

    Thanks Allan,

    I want to return a set of n records to table A. Search table A to locate the record (say on page 2, row 3). One of the cells in row 3 is representative of mJoin data, so I have a click event linking to a second table B.

    Once I have finished with table B, I return to Table A, with the pagination starting at page2, row 3. Meaning that the newly edited row is at the top of the table on page 2 (as I thought it's easier to see).

    HOWEVER! I changed approach and decided to highlight the edited row so user can easily see the edited row upon return to Table A. That way I can keep with pagination as per how datatables is intended to work (as per your helpful comment).

    Thank you for your suggestion. This can be closed.

This discussion has been closed.