如何获得过滤行数 [英] How to get filtered row count

查看:134
本文介绍了如何获得过滤行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在过滤后得到我的表的行数,但是我甚至不能让它以最初的行计数回应。



我的表格是通过HTML5渲染,由PHP填充,这些都可以正常工作。

 < table id =table_booksclass =table datatabledata-searchplaceholder =搜索书籍...data-margindifference =70> 
< thead>
< tr>
< th style =width:30px;>< i class =fa fa-codetitle =click>< / i>< / th&
< Th> Column1< / th>
< Th> Column2< / th>
< Th> Column3< / th>
< th class =text-right hidden-xsstyle =width:20%>细节< / 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方法。 p>

它返回一个对象,例如:

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


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);
});

解决方案

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

这篇关于如何获得过滤行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆