2015-07-01 49 views
4

我一直在试图获得过滤后我的表的行数,但我甚至无法让它最初回应行计数。如何获得过滤的行数

我的表格通过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); 
}); 

回答

17

使用page.info() API方法,以获取有关该表寻呼信息。

它返回一个对象,例如:

{ 
    "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; 
}