cant preserve pagination with continual refresh

cant preserve pagination with continual refresh

kittleskittles Posts: 6Questions: 0Answers: 0
edited February 2012 in General
I update a table with an ajax call repeatedly, but the pagination jumps back to 1 every time the ajax callback fires. This may be deliberate for cases where you were on page 5, and the new data means there is no page 5 anymore, but I was wondering how I could adjust the behavior to either handle this case (maybe go to last page), or at the very least, stop the pagination from going back to 1 with each refresh (and occasionally crash everything)

Here is my code:
var tableSettings = {
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
"aoColumns": [
{"sType":"numeric", "bVisible":false},
{"sType":"numeric", "iDataSort": 5},
var oTable = $('#example').dataTable(tableSettings);
var refreshId = setInterval(function() {
oTable.fnReloadAjax('/get_data', null, true);
}, 1000);
} );

Thanks for everything Allan (and anyone else who has contributed)!


  • allanallan Posts: 48,664Questions: 1Answers: 7,069 Site admin
    I think this is probably as simple as removing line 24 in the above code block - fnReloadAjax will do a draw for you (a standing redraw as you have it setup), while fnDraw will do a complete redraw, including a full sort and filter - hence resetting the paging.

  • kittleskittles Posts: 6Questions: 0Answers: 0
    Hey Allan- thanks for responding. I tried removing line 24, but pagination is still a problem. My full table initialization code is here ( if you are curious. I'll continue to bang around on things :)
  • the3rdbitthe3rdbit Posts: 8Questions: 0Answers: 0
    edited June 2012
    I just found the solution for the problem. If kittles doesn't need it anymore, at least for the documentation.

    Function to be set before the DataTable initialisation:
    $.fn.dataTableExt.oApi.fnStandingRedraw = function(oSettings) {
    if(oSettings.oFeatures.bServerSide === false){
    var before = oSettings._iDisplayStart;


    // iDisplayStart has been reset to zero - so lets change it back
    oSettings._iDisplayStart = before;

    // draw the 'current' page

    Refresh the table content:
    $(document).ready(function() {
    var oTable = $('.dataTable').dataTable()
    } );

    Copied this code from here:
This discussion has been closed.