displayStart issue

displayStart issue

applikapplik Posts: 6Questions: 2Answers: 0

Hi, I use the following code :

$('#myTable').DataTable({
    searching:false,
    responsive:true,
    lengthMenu:false,
    pageLength:10,
    displayStart:1,
    language: {
        emptyTable:"Aucune association",
        paginate: {
        previous:"Précédent",
        next:"Suivant"
        }
    },// language
    'dom':'tp'
}); // DataTable

In my example, I have 13 rows, and the page length is set to 10. So I have 2 pages.

With the value of "1" in "displayStart", the highlighted page number is "2", but the actual displayed page is the first one.

Please note that I understand the way "displayStart" is supposed to work : we have to pass the index of the row we want to be displayed. In my case it should be "13", but it does not work at all (that's why I tried the value of "1").

I have tried to use the page() method of the API but I get the "page() is not a function" javascript error.

What am I doing wrong here ?

Thanks

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    The displayStart docs indicate that if you have 10 rows and want to start on the second page you should use a value of 10. You are correct that if you use 1 it will display starting at the 2nd row but also indicate its on page 2. @allan can probably comment on why this occurs. But it seems you should use a number divisible by the page length.

    I have tried to use the page() method of the API but I get the "page() is not a function"

    Without seeing how you are trying this its hard to say. But the following should work:
    $('#myTable').DataTable().page(1);

    If you are interested in displaying the page a particular row is on then you might be interested in this plug-in:
    https://datatables.net/plug-ins/api/row().show()

    Kevin

  • applikapplik Posts: 6Questions: 2Answers: 0

    OK Kevin, thank you.

    I did not understand that the value of displayStart had to be a multiple of the pageLength.

    I think I should have it working now.

This discussion has been closed.