我一直在尝试过滤后获取表的行数,但是我什至无法使它最初以行数作为响应。

我的表格是通过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方法获取有关表的分页信息。

它返回一个对象,例如:

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

关于javascript - 如何获得过滤的行数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31163428/

10-12 00:01
查看更多