javascript 如何获得过滤的行数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31163428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get filtered row count
提问by Joel Has Simple Questions
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.
我的表格是通过 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>
I found documentation that says this works in 1.9, but I get an invalid function
我发现文档说这在 1.9 中有效,但我得到了一个无效的函数
$(document).ready(function() {
var btable = $('#table_books').DataTable();
var b_table_count = btable._('tr', {"filter":"applied"});
console.log(b_table_count);
});
回答by Gyrocode.com
Use page.info()
API method to get paging information about the table.
使用page.info()
API 方法获取有关表的分页信息。
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;
}