Jump to Page
Jump to Page
BlackPMetall
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
This discussion has been closed.
Answers
You can use
page()
to jump to a specific page.Kevin
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
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
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
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:
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.
the other approach is to have a timeout, as in this example.
Hopefully second time lucky with the solution!
Cheers,
Colin
Perfect. Thank you. It works