Trying to use fnReloadAjax to automatically refresh the table

Trying to use fnReloadAjax to automatically refresh the table

GekitsuuGekitsuu Posts: 2Questions: 0Answers: 0
edited September 2011 in General
[code]

var oTable;
$(document).ready(function() {
oTable = $('#alarms').dataTable({
"bPaginate": false,
"bProcessing": true,
"sAjaxSource": '/alarms',
"bStateSave": true,
"aoColumns" : [
{ "mDataProp": "level" },
{ "mDataProp": "robot" },
{ "mDataProp": "message" },
{ "mDataProp": "source" },
{ "mDataProp": "pool" },
{ "mDataProp": "arrival" },
{ "mDataProp": "hub" },
{ "mDataProp": "nimid" },
{ "mDataProp": "subsys" },
]

});
setInterval(function()
{
oTable.fnReloadAjax();
},30000);

} );

[/code]
Here is what my javascript looks like but I get "Uncaught TypeError: Object [object Object] has no method 'fnReloadAjax'" like oTable isn't the dataTable object when the refresh interval comes up. Can someone please help me understand where my mistake is?

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    fnReloadAjax is not part of DataTables core. as a plug-in, you need to add the code yourself to your javascript file:
    http://www.datatables.net/plug-ins/api#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, [], 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
  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    Example of adding a plug-in API method: http://datatables.net/release-datatables/examples/plug-ins/plugin_api.html

    Allan
  • GekitsuuGekitsuu Posts: 2Questions: 0Answers: 0
    Thanks, that worked perfectly!
This discussion has been closed.