javascriptjquerydatatable

How to count the entire number of rows in a datatable


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


Solution

  • 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/