Jump to Page

Jump to Page

BlackPMetallBlackPMetall Posts: 4Questions: 1Answers: 0

Hi,

i have a problem to jump directly to a page or row by start.
I want to jump by load directly to another page or row.
Here my Code:

 table = $(\'#example\').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": "data.php",
"rowId": "nr",
    "columns": [
        {
            "className":      "details-control",
            "orderable":      false,
            "data":           null,
            "defaultContent": ""
        },
        { "data": "nr" },
        { "data": "name" },
        { "data": "total" },
        { "data": "datum" },
        { "data": "status" }
    ],
"order": [[1, "desc"]]
} );

What should i do?

Thank you
Arian

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    You can use page() to jump to a specific page.

    Kevin

  • BlackPMetallBlackPMetall Posts: 4Questions: 1Answers: 0

    Hi Kevin,

    thank you for your answer. I tried already. It works if i use a button to change the page by page(). But it doesnt work if want to jump onload to the page 2.

    I tried this:

    table = $(\'#example\').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": "data.php",
    "rowId": "nr",
    "columns": [
    {
    "className": "details-control",
    "orderable": false,
    "data": null,
    "defaultContent": ""
    },
    { "data": "nr" },
    { "data": "name" },
    { "data": "total" },
    { "data": "datum" },
    { "data": "status" }
    ],
    "order": [[1, "desc"]]
    } );
    table.page( 2 ).draw( false );

    It doesnt work. What shoud i do?

    Thank you
    Arian

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi Arian,

    It's not working because the Ajax call is asynchronous - the data won't be there when the page is trying to flip to number 2. The way to go is to use the init event, which is triggered after the data has loaded.

    Take a look at the live example here.

    Cheers,

    Colin

  • BlackPMetallBlackPMetall Posts: 4Questions: 1Answers: 0

    Hi Colin,

    thank you for the example. I can see that selected page by page-nav change to 2 or 3. But the data dont change. I see always the same data by different pages.
    Whats wrong?

    Cheers
    Arian

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi again,

    Yep, you're right, I just noticed that. It's doing the second draw, while in the middle of the previous draw, so we'll change the code so that won't be possible. In the meantime, there's two approaches you can take:

    1. just jump to the row as in this example. Default paging is 10 rows per page, so displayStart set to 10 means start on the second page.

    2. the other approach is to have a timeout, as in this example.

    Hopefully second time lucky with the solution!

    Cheers,

    Colin

  • BlackPMetallBlackPMetall Posts: 4Questions: 1Answers: 0

    Perfect. Thank you. It works :)

This discussion has been closed.