jquery datatables页数的行数 [英] jquery datatables row count across pages
问题描述
有没有办法获取表中行数的行数?
例如,如果我的表中有 70
行,我们假设 50
显示在第一页,第二页上显示 20
。有没有办法获得 70
的计数?
我已经尝试了这篇文章中包含的所有建议:
jQuery:计数表中的行数
这包括:
var rowCount = $('#myTable tr ').length;
var rowCount = $('#myTable tr')。size();
var rowCount = $('#myTable> tbody> tr')。length;
var rowCount = $(#myTable)。attr('rows')。length;
但是,上述所有建议似乎返回现有页面上的行数(在这种情况下, 50
而不是 70
)。
看起来DataTables正在从DOM中移除当前页面上不存在的行,所以你不可能用jQuery选择器来计数它们。您必须使用 DataTables API ,特别是使用 fnGetData
function:
$(document).ready(function(){
//初始化你的表
var oTable = $('#myTable')。dataTable();
//获取长度
alert(oTable.fnGetData()。length);
});
I'm using the jQuery DataTables plug-in for my HTML table.
Is there a way to get the row count of the number of rows in my table across pages.
For example, if I have 70
rows in my table, and let's say 50
of them get displayed on the 1st page, and 20
on the 2nd page. Is there a way to get the count of 70
?
I've tried all the suggestions included in this post: jQuery: count number of rows in a table
This includes:
var rowCount = $('#myTable tr').length;
var rowCount = $('#myTable tr').size();
var rowCount = $('#myTable >tbody >tr').length;
var rowCount = $("#myTable").attr('rows').length;
But all the above suggestions seem to return the number of rows on the existing page (in this case, 50
and not 70
).
It looks like DataTables is removing the rows that aren't on the current page from the DOM, so you aren't going to be able to count them with a jQuery selector. You'll have to use the DataTables API, specifically the fnGetData
function:
$(document).ready(function() {
// Initialize your table
var oTable = $('#myTable').dataTable();
// Get the length
alert(oTable.fnGetData().length);
} );
这篇关于jquery datatables页数的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!