Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82017

fnReloadAjax - Count rows before & after

$
0
0
I'm trying to tell if an ajax request has pulled new rows, and refresh the page if it has.

// AJAX this and get results to repopulate table every 10 seconds
    setInterval(function() {
        
       // Get the old length
        var oTable = $('.dataTable').dataTable();
        oldLength = oTable.fnGetData().length;
        console.log('Old: '+oldLength);

        // AJAX it
        oTable.fnReloadAjax();

       // Get the new length        
        oTable = $('.dataTable').dataTable();
        newLength = oTable.fnGetData().length;
        console.log('New: '+newLength);
        
        // If any changes have been made, reload page
        if(oldLength != newLength)
        {
            //document.location.reload(); 
            console.log('CHANGED');
        }
    }, 10000);

The two console.logs's ALWAYS show the same number. Why aren't they getting the length correctly?

Viewing all articles
Browse latest Browse all 82017

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>