leora leora - 2 years ago 112
Javascript Question

Is there any way to get the current record count in a HTML table that's using jQuery datatable plugin

I tried using this:

var rowCount = $('#locationsTable tbody tr').length - 1;

But the one issue is that you can't tell if there is 1 record in the table or 0 records because, when there are 0 records, the jQuery datatable plugin shows one extra
row that says "No records matched".

Is there a better way to get actual valid row/record count?

Answer Source

Try this:

var oTable;
$(document).ready(function() {
    oTable = $('#example').dataTable();
    var oSettings = oTable.fnSettings();
    alert( oSettings.fnRecordsTotal() );
    alert( oSettings.fnRecordsDisplay() );
    alert( oSettings.fnDisplayEnd() );

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