Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get filtered row count

I have been trying to get the row count of my table after filtering, but I can't even get it to respond back with the row count initially.

My table is rendered via HTML5 and populated by PHP which all works correctly.

<table id="table_books" class="table datatable" data-searchplaceholder="Search books..." data-margindifference="70" >
 <thead>
 <tr>
  <th style="width:30px;"><i class="fa fa-code" title="click"></i></th>
  <th>Column1</th>
  <th>Column2</th>
  <th>Column3</th>
  <th class="text-right hidden-xs" style="width:20%">Details</th>
 </tr>
 </thead>
<tbody>
 <?php echo $contenthtml; ?>
</tbody>
</table>

I found documentation that says this works in 1.9, but I get an invalid function

$(document).ready(function() {
 var btable = $('#table_books').DataTable();
 var b_table_count = btable._('tr', {"filter":"applied"});
 console.log(b_table_count);
});
like image 984
Joel Has Simple Questions Avatar asked Jul 01 '15 13:07

Joel Has Simple Questions


1 Answers

Use page.info() API method to get paging information about the table.

It returns an object, for example:

{
    "page": 1,
    "pages": 6,
    "start": 10,
    "end": 20,
    "length": 10,
    "recordsTotal": 57,
    "recordsDisplay": 57
}

Usage:

function getNumFilteredRows(id){
   var info = $(id).DataTable().page.info();
   return info.recordsDisplay;
}
like image 106
Gyrocode.com Avatar answered Nov 15 '22 19:11

Gyrocode.com