Table rows count from multiple pages
In Javascript, I have a table that contains multiple rows (100 rows). In my UI, I can show only 20 rows per page开发者_运维问答. So, these rows are displayed in 5 pages.
When I am trying to get the row count of the table using tbl.rows.length, it is giving me only 20 not 100.
In this scenario, which function can I use to get the total count of the rows?
There's no good way to do this with javascript alone, unless you have something like Showing 1-20 of <span id="num_rows">100</span>
, then you can grab the content of that span.
Using AJAX to query the server seems like overkill.
One way or another, you should probably just insert the total rows value into your html somewhere, and just read the value with javascript. You could even set an attribute like data-total_rows="100"
to the table if you desire - there are plenty of options.
Whatever you choose using this method, the value would have to be updated as well if you are dynamically adding/removing rows.
精彩评论