How do I get the number of rows that match a filter?

How do I get the number of rows that match a filter?

AlviiAlvii Posts: 15Questions: 4Answers: 2

I want to show the number of rows that have an specific value in a certain column, for example, count all the rows that have the value 'Active' in the column 9 field. Let's pretend there are 233 rows that match that filter, so I want to show a box that says "Active: 233" in some place of the page.

My problem is that, no mather if i use the filter() or the search() method, it always returns all the table rows without applying the filter.

I tried:

table.column(9).data().filter(function (value, index) {return value = "Active" ? true : false;}).length;
table.column(9).data().search("Active").length;
table.column(9).search("Active").data().length;

And a lot of similar variants with no luck. How can I get a simple value showing how many rows match the filter/search function?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765
    Answer ✓

    value = "Active"

    Using = assigns the value to a variable. You need to use a comparison operator like == or ===.

    Kevin

This discussion has been closed.