Saving the page of the datatable on page refresh

Saving the page of the datatable on page refresh

sinceresincere Posts: 7Questions: 0Answers: 0
edited April 2012 in General
Hi I am using jQuery datatable ver 1.8.0 and having hard time saving the pagination on page refresh. In other words, if I am on page 5 and I refresh the browser (F5) , I want the table to start from page 5 which is not happening, no matter what I do.

Note that I am using server side processing i.e. bServerSide = true;
Below is the code snippet that I think is relevant

fnServerData": function ( url, data, callback, settings ) {
var loadPageAt= trainList.fnSettings()._iDisplayStart;
alert(loadPageAt);
data.push( { "name": "iDisplayStart", "value": loadPageAt} );
settings.jqXHR = $.ajax( {
"url": url,
"type": "POST",
"data": data,
"success": function(json) {
userListTable.fnSettings()._iDisplayStart = json.iDisplayStart;
callback(json);
}
}
Note that when I click to a certain page number (assume iDisplayLength 10) , the alert in the code give me the right value i.e. if I click on page 5 - 40 is alerted. However, at this point, if I refresh, the alert value is now 0.

Please advise.

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Use bStateSave to turn on state saving.

    Allan
  • sinceresincere Posts: 7Questions: 0Answers: 0
    Hi Allan, Thanks for your quick response but I forgot to mention in my original post that I have "bStateSave": true already.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    The state saving built into DataTables should work as is - as shown in this example: http://datatables.net/release-datatables/examples/basic_init/state_save.html

    I'd suggest removing the iDisplayStart stuff from fnServerData and seeing if the built in state saving does the trick for you. If not, can you link us to a test case showing it not working?

    Allan
  • sinceresincere Posts: 7Questions: 0Answers: 0
    Hi Allan, Let me give that a shot. Thanks much..
  • sinceresincere Posts: 7Questions: 0Answers: 0
    Hi Allan, I tried removing the iDisplayStart stuff from the fnServerData but of no help. We call a controller method to get the train data and iDisplayStart is a request parameter in that method. I noticed that iDisplaystart is always set to 0 on page refresh in this method. However, if I simply jump to a different page, this value is what it should be as in iDispalystart = 30, 40 , 50 etc between page jumps. Does that tell you anything ? I am thinking, the jQuery Datatable on tear down set the iDisplayStart to 0.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Not really I'm afraid since it works in my test cases. There must be a call you are making or something that is causing that to be overridden.

    > I am thinking, the jQuery Datatable on tear down set the iDisplayStart to 0.

    Tear down as in fnDestroy? Yes it does. Are you making that call?

    Allan
This discussion has been closed.