【问题标题】:How to get filtered row count如何获得过滤的行数
【发布时间】:2015-09-18 17:38:11
【问题描述】:

我一直在尝试在过滤后获取表格的行数,但我什至无法让它最初回复行数。

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

【问题讨论】:

    标签: javascript php html datatables


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-08
      • 1970-01-01
      • 2011-07-23
      • 2012-09-21
      • 1970-01-01
      • 2022-01-23
      相关资源
      最近更新 更多