我正在使用数据表以JSON格式显示一些数据,并且我在JSON的底部包括了查询总数,如下所示:
{
"data": [
{
"id": "1",
"provider_num": "381301",
"provider_name": "COTTAGE GROVE COMMUNITY HOSPITAL",
"261_total_bad_debts": "$0",
"271_medicare_bad_debts": "$79,275",
"281_non_medicare_bad_debts": "$-79,275",
"1_cost_to_charge_ratio": "0.703459",
"291_cost_of_non_mcr_bad_debts": "$-55,767"
}
],
"total_bad_debts": 0,
"total_medicare_bad_debts": 79275,
"total_non_medicare_bad_debts": -79275,
"total_cost_of_non_mcr_bad_debts": -55767
}
我对如何将它们添加到表的页脚中感到有些困惑,就像之前我可以直接访问php变量一样,现在我将它们编码为JSON。如果有人对此有任何经验,并且在数据表初始化中使用footerCallback
确实很棒。
提前感谢
您可以在DataTables页脚中使用来自JSON响应的数据,如下所示。
$('#example').dataTable( {
'ajax': 'data/arrays.txt',
'footerCallback': function( row, data, start, end, display ) {
var api = this.api();
var response = this.api().ajax.json();
if (response) {
$(api.column(3).footer()).html(
response.total_bad_debts
);
$(api.column(4).footer()).html(
response.total_medicare_bad_debts
);
$(api.column(5).footer()).html(
response.total_non_medicare_bad_debts
);
$(api.column(6).footer()).html(
response.total_cost_of_non_mcr_bad_debts
);
}
}
});