cant preserve pagination with continual refresh
cant preserve pagination with continual refresh
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:
[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);
} );
[/code]
Thanks for everything Allan (and anyone else who has contributed)!
Here is my code:
[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);
} );
[/code]
Thanks for everything Allan (and anyone else who has contributed)!
This discussion has been closed.
Replies
Allan
Function to be set before the DataTable initialisation:
[code]
$.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);
};
[/code]
Refresh the table content:
[code]
$(document).ready(function() {
var oTable = $('.dataTable').dataTable()
oTable.fnStandingRedraw();
} );
[/code]
Copied this code from here:
http://datatables.net/plug-ins/api