如何计算数据表中的总行数
How to count the entire number of rows in a datatable
我正在为我的应用程序使用数据表。如何获取数据表 onload
中的总行数?我的代码:
$(document).ready( function() {
$('#jobSearchResultTable').dataTable({
responsive: true,
"scrollY": 500,
"scrollCollapse": true,
"jQueryUI": true,
"aaSorting": []
});
)};
如何获取数据表中的总行数onload
根据您的描述,我假设您有 table,id="jobSearchResultTable"。
试试这个对你有用。
$(document).ready( function() {
$('#jobSearchResultTable').dataTable({
responsive: true,
"scrollY": 500,
"scrollCollapse": true,
"jQueryUI": true,
"aaSorting": []
});
var count=0;
$('#jobSearchResultTable tr').each(function(){
count++;
});
alert(count);
)};
这将显示 table 中的行数。
新版本更新
table.data().count()
参考:https://datatables.net/reference/api/count()
旧版本:
$(document).ready(function() {
//Initialize your table
var table = $('#jobSearchResultTable').dataTable();
//Get the total rows
alert(table.fnGetData().length);
});
来源:
另一种方法:
table.fnSettings().fnRecordsTotal();
看看哪一个适合你
来源:http://datatables.net/forums/discussion/2278/how-to-get-number-of-rows/
//获取整行数
table.rows().eq(0).length;
如果您使用的是新的 DataTables (v1.10+),您将无法访问某些遗留函数,例如 fnGetData()。
相反,试试这个:
var table = $('#table_id').DataTable();
var table_length = table.data().count();
如果您正在使用分页(我就是这样),并且需要所有页面的总计数,试试这个:
var table = $('#table_id').DataTable({
'paging': true
});
var length = table.page.info().recordsTotal;
来源:
$('#jobSearchResultTable').dataTable().rows().count()
我刚刚在控制台中读取了 table 实例并在版本 1.10.8 中得到了这个
var table = $("#mytable").DataTable({})
var total = table.settings()[0].json.recordsTotal
希望对您有所帮助
请查看以下代码
var table = $('#example').DataTable();
alert(
'Number of row entries: '+
table
.column( 0 )
.data()
.length
);
按照适合我的方式从服务器端处理获取响应:
// tested with : DataTables 1.10.15
t1 = $('#item-list').DataTable({
"processing": true,
"serverSide": true,
"ajax":'url',
"drawCallback": function( settings, start, end, max, total, pre ) {
console.log(this.fnSettings().json); /* for json response you can use it also*/
alert(this.fnSettings().fnRecordsTotal()); // total number of rows
},
...
});
我尝试了答案中的大部分解决方案,但对我没有用。
有些工作,但是当我们搜索时,它显示相同的数字而不是搜索后的行数。
var tbl=$('#tbl_name').DataTable();
console.log(tbl['context'][0]['aiDisplay'].length);
即使在搜索之后它也对我有用,显示搜索后的当前行数。
2021 年 10 月 Yajra 数据表
myTable.rows().count();
我正在为我的应用程序使用数据表。如何获取数据表 onload
中的总行数?我的代码:
$(document).ready( function() {
$('#jobSearchResultTable').dataTable({
responsive: true,
"scrollY": 500,
"scrollCollapse": true,
"jQueryUI": true,
"aaSorting": []
});
)};
如何获取数据表中的总行数onload
根据您的描述,我假设您有 table,id="jobSearchResultTable"。
试试这个对你有用。
$(document).ready( function() {
$('#jobSearchResultTable').dataTable({
responsive: true,
"scrollY": 500,
"scrollCollapse": true,
"jQueryUI": true,
"aaSorting": []
});
var count=0;
$('#jobSearchResultTable tr').each(function(){
count++;
});
alert(count);
)};
这将显示 table 中的行数。
新版本更新
table.data().count()
参考:https://datatables.net/reference/api/count()
旧版本:
$(document).ready(function() {
//Initialize your table
var table = $('#jobSearchResultTable').dataTable();
//Get the total rows
alert(table.fnGetData().length);
});
来源:
另一种方法:
table.fnSettings().fnRecordsTotal();
看看哪一个适合你
来源:http://datatables.net/forums/discussion/2278/how-to-get-number-of-rows/
//获取整行数
table.rows().eq(0).length;
如果您使用的是新的 DataTables (v1.10+),您将无法访问某些遗留函数,例如 fnGetData()。
相反,试试这个:
var table = $('#table_id').DataTable();
var table_length = table.data().count();
如果您正在使用分页(我就是这样),并且需要所有页面的总计数,试试这个:
var table = $('#table_id').DataTable({
'paging': true
});
var length = table.page.info().recordsTotal;
来源:
$('#jobSearchResultTable').dataTable().rows().count()
我刚刚在控制台中读取了 table 实例并在版本 1.10.8 中得到了这个
var table = $("#mytable").DataTable({})
var total = table.settings()[0].json.recordsTotal
希望对您有所帮助
请查看以下代码
var table = $('#example').DataTable();
alert(
'Number of row entries: '+
table
.column( 0 )
.data()
.length
);
按照适合我的方式从服务器端处理获取响应:
// tested with : DataTables 1.10.15
t1 = $('#item-list').DataTable({
"processing": true,
"serverSide": true,
"ajax":'url',
"drawCallback": function( settings, start, end, max, total, pre ) {
console.log(this.fnSettings().json); /* for json response you can use it also*/
alert(this.fnSettings().fnRecordsTotal()); // total number of rows
},
...
});
我尝试了答案中的大部分解决方案,但对我没有用。
有些工作,但是当我们搜索时,它显示相同的数字而不是搜索后的行数。
var tbl=$('#tbl_name').DataTable();
console.log(tbl['context'][0]['aiDisplay'].length);
即使在搜索之后它也对我有用,显示搜索后的当前行数。
2021 年 10 月 Yajra 数据表
myTable.rows().count();