luc*_*fer 3 javascript datatable jquery
我正在为我的应用程序使用数据表.如何获取数据表中行的总数onload?我的代码:
$(document).ready( function() {
$('#jobSearchResultTable').dataTable({
responsive: true,
"scrollY": 500,
"scrollCollapse": true,
"jQueryUI": true,
"aaSorting": []
});
)};
Run Code Online (Sandbox Code Playgroud)
如何获取数据表中的总行数 onload
Ruc*_*han 11
$(document).ready(function() {
//Initialize your table
var table = $('#jobSearchResultTable').dataTable();
//Get the total rows
alert(table.fnGetData().length);
});
Run Code Online (Sandbox Code Playgroud)
资料来源:https://stackoverflow.com/questions/3238047/jquery-datatables-row-count-across-pages
另一种方法:
table.fnSettings().fnRecordsTotal();
Run Code Online (Sandbox Code Playgroud)
看看哪一个适合你
资料来源:http://datatables.net/forums/discussion/2278/how-to-get-number-of-rows/
小智 10
如果您正在使用新的DataTables(v1.10 +),则无法访问某些标准功能,例如fnGetData().
相反,试试这个:
var table = $('#table_id').DataTable();
var table_length = table.data().count();
Run Code Online (Sandbox Code Playgroud)
如果您正在使用分页(我是),并且需要所有页面的总计数,请尝试以下方法:
var table = $('#table_id').DataTable({
'paging': true
});
var length = table.page.info().recordsTotal;
Run Code Online (Sandbox Code Playgroud)
资料来源:
https://datatables.net/reference/api/count()
https://datatables.net/reference/api/page.info()
按照对我有用的方式从服务器端处理获取响应:
// 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
},
...
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41164 次 |
| 最近记录: |