Count number of rows before and after reload

Count number of rows before and after reload

ChrisFChrisF Posts: 15Questions: 7Answers: 0

I have set an interval to reload the DataTable every XY seconds, what I want to do is count the number of rows before the reload, and after, in case the number of rows are higher after the refresh I want to display an alert that a new reservation was made.

This is the code:

setInterval( function () {


                                var  rows = table.rows().count();
                                table.ajax.reload();
                                var  rows2 = table.rows().count();

                                if(rows2>rows) {
                                    alert('New reservation');
                                }
                            }, 3000 );

The output of rows and rows2 are the same, which are the number of rows AFTER the reload.
I looked at this post: https://datatables.net/forums/discussion/12613/fnreloadajax-count-rows-before-after
but couldnt get it to work, newLength = table.fnGetData().length; outputs nothing

Answers

  • ChrisFChrisF Posts: 15Questions: 7Answers: 0

    I alredy figured it out in the meantime:

             setInterval( function () {
    
    
                                    var  rows = table.rows().count();
    
                                    table.ajax.reload( function () {
                                        var  rows2 = table.rows().count();
                                        if(rows2>rows) {
                                            alert("NEW RESERVATION!");
                                        }
                                    } );
                                }, 30000 );
    
Sign In or Register to comment.