我有这样的jquery请求:
jQuery(function()
{
jQuery('#numberList').dataTable({
"processing": true,
"serverSide": true,
"ajax": "${baseURL}voip/provisioning/ajax/dtsearch/" + addType,
"columns": [
{ "data": "number" },
{ "data": "type" },
{ "data": "targetDisplay" },
{ "data": "lastChanged" },
{ "data": "triple9Data" },
{ "data": "portingIn" },
{ "data": "edit" }
],
"columnDefs": [
{
"render": function (data, type, row) {
row.edit = '<input id="numberCheckbox' + row.id + '" type="checkbox" name="number" value="' + row.id + '"/>';
return data;
},
"targets": 0
},
]
});
jQuery("#list_filter label input").attr("placeholder", "search...");
});
我需要访问。
$("#pager_total").text(recordsFiltered);
每次JSON返回时。但我无法访问:
recordsFiltered
如何访问它?
$("#pager_total").text(data.length);
答案 0 :(得分:1)
找到解决方案:
$('#some_table').DataTable({
// your regular call... ,
drawCallback: function() {
var api = this.api();
var num_rows = api.page.info().recordsTotal;
var records_displayed = api.page.info().recordsDisplay;
// now do something with those variables
}
});
在我的情况下返回16784,这是我正在搜索的记录总数。
答案 1 :(得分:0)
获取recordsFiltered
或recordsTotal
的另一种方法是加入最后的JSON响应:
var countBeforeFiltering = table.ajax.json().recordsTotal;
var countAfterFiltering = table.ajax.json().recordsFiltered;