counter in rowCallback

counter in rowCallback

antoniocibantoniocib Posts: 277Questions: 62Answers: 1
rowCallback: function ( row, data, ) {                                                                                                                  
    var count=[];
    var today = new Date;
    if ( new Date( data.data_scadenza ) <  today){
        count++;
            }
console.log(count);
        },

Hi guys, where i wrong?

This question has an accepted answers - jump to answer

Answers

  • antoniocibantoniocib Posts: 277Questions: 62Answers: 1

    Okay my bad,
    I put the array inside the rowCallback and it was always reset

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421
    Answer ✓

    a counter should be an integer variable not an array.
    In addition since rowCallback is called for every row you would need a global variable if you want to count the number of rows meeting a condition.

    //global variable, make sure it is initialized properly
    var count = 0;
    
    rowCallback: function ( row, data, ) {                                                                                                                 
        var today = new Date;
        if ( new Date( data.data_scadenza ) <  today){
            count++;
                }
    console.log(count);
            },
    
Sign In or Register to comment.