leora leora - 9 months ago 25
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?


Try this:

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

} );