如何获取过滤后的行数

How to get filtered row count

我一直试图在过滤后获取 table 的行数,但我什至无法让它最初响应行数。

我的 table 通过 HTML5 呈现并由 PHP 填充,一切正常。

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

我发现文档说这在 1.9 中有效,但我得到一个无效函数

$(document).ready(function() {
 var btable = $('#table_books').DataTable();
 var b_table_count = btable._('tr', {"filter":"applied"});
 console.log(b_table_count);
});

使用page.info()API方法获取关于table的分页信息。

它returns一个对象,例如:

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

用法:

function getNumFilteredRows(id){
   var info = $(id).DataTable().page.info();
   return info.recordsDisplay;
}