How to count rows with a match value?

How to count rows with a match value?

grrdchvzsgrrdchvzs Posts: 2Questions: 1Answers: 0

I need to count the number of rows with a specific value and display it in the HTML document.
I use AJAX method POST with a PHP file.

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Use rows() with the row-selector as a function to match your criteria. Chain count() to get the resulting row count.

    Kevin

  • grrdchvzsgrrdchvzs Posts: 2Questions: 1Answers: 0
    edited August 2022

    initComplete: function() {
    console.log(tableArchives.rows('anyvalue').count());
    }

    I tried it this way and had no results

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited August 2022

    Look at the function example in the row-selector docs.

    The variable tableArchives is likely not available in initComplete. Instead use this.api(). Something like this:

    initComplete: function () {
      var count = this.api()
        .rows( function ( idx, data, node ) {
            return data.first_name.charAt(0) === 'A' ?  // Replace this with your condition
                true : false;
        } )
        .count();
      console.log( count );
    }
    

    Kevin

Sign In or Register to comment.