How to use the displayPage option

How to use the displayPage option

hulk66049hulk66049 Posts: 2Questions: 1Answers: 0

I have a situation where I need to be able to load my datatable to a specific page. Here's what's going on. The site I'm working on is using an ajax call to load the standard html table, followed by the datatable inititalization using the following code:

staffMsgs = $('#staff-messages').DataTable({
"ordering": false,
"searching": true,
"lengthChange": false,
"pageLength": 20,
"displayStart": page
});

There are some controls on the page that allow the user to search, filter, etc the table, which again, uses ajax to load the table, then initializes the table. One of the buttons is a refresh button. When the user presses the refresh button, I'm grabbing the current page number using:

staffMsgs.page.info()

and passing the page parameter back to the datatable initialization (multiplied by 20), so if the user is on page 2 and hits the "refresh" button, it passes a value of 20 to the displayStart option. When debugging the code, the var is set correctly, but when the datatable is loaded, it continues to load starting with row 0.

I've attempted to manually set the displayStart to 20 just for testing, and nothing I do will load up my table to the second page.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,903Questions: 1Answers: 10,148 Site admin
    Answer ✓

    Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged. The code you show above appears to be correct. Here is a copy and paste of your code above that shows it working: http://live.datatables.net/xerubazi/1/edit .

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    Thanks,
    Allan

  • hulk66049hulk66049 Posts: 2Questions: 1Answers: 0

    Thanks for the reply. What I was really looking for was making sure I was using this in the correct manner, which your example confirmed that I was. This allowed me to start looking elsewhere, which I realized that after initializing the table, I was checking if I had a search parameter and redrawing the table. I reworked my code to pass an initial search parameter into the initialization object and everything is working great. Thanks for your help!

This discussion has been closed.