fnReloadAjax with fnStandingRedraw
fnReloadAjax with fnStandingRedraw
New to DataTables, and so far very pleased with what it can do. I am having one minor issue and after searching the forums and trying a few things am unable to resolve this issue.
I load data for the table via a PHP script which is called in the sAjaxSource setting, I run a reload of the data every 30 secs to get any changes or new records via fnReloadAjax on a javascript timer. However when it reloads it dumps you back to page 1 of the table. How do I get it to retain the current page that your on?
Here is my code:
[code]
$(document).ready(function () {
inMsg = $('.inboundmsg').dataTable( {
'bProcessing': true,
'bLengthChange': true,
'bPaginate': true,
'sPaginationType': 'full_numbers',
'iDisplayLength': 5,
'bInfo': false,
'bStandingRedraw': true,
'aaSorting': [[ 5, "desc" ]],
'oLanguage':
{
'sSearch': 'Search:',
'sProcessing': ' Refreshing Data',
'oPaginate':
{
'sNext': '>',
'sLast': '>>',
'sFirst': '<<',
'sPrevious': '<'
}
},
'aoColumns': [
{ "bSortable": false },
{ "sClass": "bold left" },
{ "sClass": "sixtysix left" },
{ "sClass": "value center" },
{ "sClass": "center" },
{ "sClass": "center" },
{ "sClass": "center"},
{ "bSortable": false, "sClass": "full nowrap center" }
],
"sAjaxSource": 'includes/datacalls/DataHelper.php?action=inboundmsg&pnetid=74148&showstatus=1'
} );
setTimeout(function() { reloadTable(inMsg); },30000);
});
[/code]
Here is a copy of the simpe reloadTable function I call
[code]
var tblName;
function reloadTable(tblName){
tblName.fnReloadAjax();
setTimeout(function() { reloadTable(tblName); },30000);
}
[/code]
Any help or suggestions would be greatly appreciated.
I load data for the table via a PHP script which is called in the sAjaxSource setting, I run a reload of the data every 30 secs to get any changes or new records via fnReloadAjax on a javascript timer. However when it reloads it dumps you back to page 1 of the table. How do I get it to retain the current page that your on?
Here is my code:
[code]
$(document).ready(function () {
inMsg = $('.inboundmsg').dataTable( {
'bProcessing': true,
'bLengthChange': true,
'bPaginate': true,
'sPaginationType': 'full_numbers',
'iDisplayLength': 5,
'bInfo': false,
'bStandingRedraw': true,
'aaSorting': [[ 5, "desc" ]],
'oLanguage':
{
'sSearch': 'Search:',
'sProcessing': ' Refreshing Data',
'oPaginate':
{
'sNext': '>',
'sLast': '>>',
'sFirst': '<<',
'sPrevious': '<'
}
},
'aoColumns': [
{ "bSortable": false },
{ "sClass": "bold left" },
{ "sClass": "sixtysix left" },
{ "sClass": "value center" },
{ "sClass": "center" },
{ "sClass": "center" },
{ "sClass": "center"},
{ "bSortable": false, "sClass": "full nowrap center" }
],
"sAjaxSource": 'includes/datacalls/DataHelper.php?action=inboundmsg&pnetid=74148&showstatus=1'
} );
setTimeout(function() { reloadTable(inMsg); },30000);
});
[/code]
Here is a copy of the simpe reloadTable function I call
[code]
var tblName;
function reloadTable(tblName){
tblName.fnReloadAjax();
setTimeout(function() { reloadTable(tblName); },30000);
}
[/code]
Any help or suggestions would be greatly appreciated.
This discussion has been closed.
Replies
Allan
I have added the plugin for standingRedraw but not seeing any difference.
What is this part of the fnReloadAjax do? from what I am reading it looks like if bStandingRedraw is true then it should not be jumping back to page 1.
[code]
if ( typeof bStandingRedraw != 'undefined' && bStandingRedraw === true )
{
oSettings._iDisplayStart = iStart;
that.fnDraw( false );
}
[/code]
I get data refreshing and remaining on the same page.
I have tested this with editing existing records, will test tomorrow with a new record being added.
By adding the following lines
[code]
oSettings._iDisplayStart = iStart;
oSettings.oApi._fnCalculateEnd(oSettings)
that.fnDraw( false );
[/code]
Modified fnReloadAjax:
[code]
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
{
if ( typeof sNewSource != 'undefined' && sNewSource != null )
{
oSettings.sAjaxSource = sNewSource;
}
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;
var iStart = oSettings._iDisplayStart;
oSettings.fnServerData( oSettings.sAjaxSource, null, function(json) {
/* Clear the old information from the table */
that.oApi._fnClearTable( oSettings );
/* Got the data - add it to the table */
for ( var i=0 ; i
Allan