我正在使用数据表以 JSON格式显示一些数据,并且我在JSON的底部包含了查询总计,如下所示: { "data": [ { "id": "1", "provider_num": "381301", "provider_name": "COTTAGE GROVE COMMUNITY HOSPITAL", "261_total_bad_d
{ "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( tfoot, data, start, end, display ) { var response = this.api().ajax.json(); if(response){ var $th = $(tfoot).find('th'); $th.eq(0).html(response['total_bad_debts']); $th.eq(1).html(response['total_medicare_bad_debts']); $th.eq(2).html(response['total_non_medicare_bad_debts']); $th.eq(3).html(response['total_cost_of_non_mcr_bad_debts']); } } });