Error fnDraw() is not defined

Error fnDraw() is not defined

DenonthDenonth Posts: 76Questions: 0Answers: 0
edited June 2012 in General
Hi all,

I want to refresh data in the table every 30 sec, I was reading on this forum a lot. And I saw that for the server side processing I can call fnDraw() function every 30 sec and it will populate all new entries that are made to the table?

Here is my code:

[code]
$(document).ready(function() {
$('#jphit').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sScrollY": "350px",
"bDeferRender": true,

"oTableTools": {
"aButtons": [
"copy",
"print",
{
"sExtends": "collection",
"sButtonText": "Save",
"aButtons": [ "csv", "xls", "pdf" ]
}
]
},
"sAjaxSource": "increment_table.php"
} );

setInterval('fnDraw()',30000);

[/code]

I am getting an error that fnDraw() is not defined.

Replies

  • DenonthDenonth Posts: 76Questions: 0Answers: 0
    Any idea guys? How to make this table to fetch new data every 10 sec
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    fnDraw is not a global function - it is an API method of DataTables and you need to call it as such. See the fnDraw documentation for an example.

    Allan
  • DenonthDenonth Posts: 76Questions: 0Answers: 0
    Ok I have put it like this and it is not working:

    [code]
    $(document).ready(function() {
    var oTable = $('#jphit').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sScrollY": "350px",
    "bDeferRender": true,

    "oTableTools": {
    "aButtons": [
    "copy",
    "print",
    {
    "sExtends": "collection",
    "sButtonText": "Save",
    "aButtons": [ "csv", "xls", "pdf" ]
    }
    ]
    },
    "sAjaxSource": "increment_table.php"
    } );

    setInterval(oTable.fnDraw(),3000);

    [/code]
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    setInterval calls the callback function with global scope, but oTable is locally defined, hence why it is not working.

    You need to add an anonymous function into setInterval which will call oTable.fnDraw()

    Allan
  • DenonthDenonth Posts: 76Questions: 0Answers: 0
    Okay I have defined it and it is working but know there is a problem with saving the state what I am looking at. It keeps getting me back to the first row and resets filters. How to save the filters and state where I was?
This discussion has been closed.