How to count the entire number of rows in a datatable

Update for New Versions

table.data().count()

Reference:https://datatables.net/reference/api/count()

For older versions:

$(document).ready(function() {
 //Initialize your table
 var table = $('#jobSearchResultTable').dataTable();
 //Get the total rows
 alert(table.fnGetData().length);
});

Source: https://stackoverflow.com/questions/3238047/jquery-datatables-row-count-across-pages

Another method:

table.fnSettings().fnRecordsTotal();

see which one works for you

Source: http://datatables.net/forums/discussion/2278/how-to-get-number-of-rows/


Get response from serverside processing following way it works for me:

// tested with : DataTables 1.10.15
t1 = $('#item-list').DataTable({
    "processing": true,
    "serverSide": true,
    "ajax":'url',
    "drawCallback": function( settings, start, end, max, total, pre ) {  
        console.log(this.fnSettings().json); /* for json response you can use it also*/ 
        alert(this.fnSettings().fnRecordsTotal()); // total number of rows
    },
    ...
});

If you're using the new DataTables (v1.10+), you don't have access to some legacied functions such as fnGetData().

Instead, try this:

var table = $('#table_id').DataTable();
var table_length = table.data().count();

If you're using paging (which I was), and need the total count across all pages, try this:

var table = $('#table_id').DataTable({
    'paging': true
});

var length = table.page.info().recordsTotal;

Sources:

https://datatables.net/reference/api/count()

https://datatables.net/reference/api/page.info()