Pritish Pritish - 1 year ago 182
jQuery Question

jquery datatables row count across pages

I'm using the jQuery DataTables plug-in for my HTML table.

Is there a way to get the row count of the number of rows in my table across pages.

For example, if I have

rows in my table, and let's say
of them get displayed on the 1st page, and
on the 2nd page. Is there a way to get the count of

I've tried all the suggestions included in this post:
jQuery: count number of rows in a table

This includes:

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

var rowCount = $('#myTable tr').size();

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

var rowCount = $("#myTable").attr('rows').length;

But all the above suggestions seem to return the number of rows on the existing page (in this case,
and not

Answer Source

It looks like DataTables is removing the rows that aren't on the current page from the DOM, so you aren't going to be able to count them with a jQuery selector. You'll have to use the DataTables API, specifically the fnGetData function:

$(document).ready(function() {

    // Initialize your table
    var oTable = $('#myTable').dataTable();

    // Get the length
} );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download