I am using a datatable for my application. How do I get the total count of the rows in the datatable onload
? My code:
$(document).ready( function() {
$('#jobSearchResultTable').dataTable({
responsive: true,
"scrollY": 500,
"scrollCollapse": true,
"jQueryUI": true,
"aaSorting": []
});
)};
How to get the total count of rows in the datatable onload
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()
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With