如何过滤行数

时间:2015-07-01 13:55:56

标签: javascript php html5 datatables

我一直试图在过滤后获取我的表的行数,但我甚至无法让它最初用行计数回复。

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

1 个答案:

答案 0 :(得分:21)

使用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;
}
相关问题