cant preserve pagination with continual refresh

cant preserve pagination with continual refresh

edited February 2012 in General Posts: 6
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 = { "bStateSave":true, "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>", "sPaginationType": "bootstrap", "oLanguage": { "sLengthMenu": "_MENU_ records per page" }, "aoColumns": [ {"sType":"html"}, {"sType":"numeric"}, {"sType":"string"}, {"sType":"string"}, {"sType":"date"}, {"sType":"numeric", "bVisible":false}, {"sType":"numeric", "iDataSort": 5}, {"sType":"string"} ], "bAutoWidth":false, }; var oTable = $('#example').dataTable(tableSettings); oTable.fnReloadAjax('/get_data'); var refreshId = setInterval(function() { oTable.fnReloadAjax('/get_data', null, true); oTable.fnDraw(); }, 1000); } );
Thanks for everything Allan (and anyone else who has contributed)!

Replies

  • Posts: 21,571
    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.

    Allan
  • Hey Allan- thanks for responding. I tried removing line 24, but pagination is still a problem. My full table initialization code is here (http://hastebin.com/dabejewoco.coffee) if you are curious. I'll continue to bang around on things :)
  • edited June 2012 Posts: 8
    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; oSettings.oApi._fnReDraw(oSettings); // iDisplayStart has been reset to zero - so lets change it back oSettings._iDisplayStart = before; oSettings.oApi._fnCalculateEnd(oSettings); } // draw the 'current' page oSettings.oApi._fnDraw(oSettings); };
    Refresh the table content:
    $(document).ready(function() { var oTable = $('.dataTable').dataTable() oTable.fnStandingRedraw(); } );

    Copied this code from here:
    http://datatables.net/plug-ins/api
This discussion has been closed.