Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count the number of rows in a HTML table?

I can't seem to find this anywhere. I have a dataTable like this one, and I want to be able to count the number of rows in the dataTable in javascript. how would that be accomplished? thanks!

I need it in javascript because I want to iterate through the datatable and check to see if any rows cantain certain data in them.

EXAMPLE PSEUDOCODE

var tableSize = someway to get table size;
for (i = 0; i < tableSize; i++) {
if (dataTable.row(i).value == "someValue") {
    //do something
}
like image 329
Myy Avatar asked Dec 07 '22 13:12

Myy


1 Answers

It would be easier to count the rows with jQuery:

var tableSize = $('#myTable tbody tr').length;

Demo: http://jsfiddle.net/YLVuK/1/

like image 68
GG. Avatar answered Dec 11 '22 09:12

GG.