数据表“footerCallback”函数未在页脚中显示结果

2024-05-15

我尝试获取每列的总和并将结果显示在页脚中。我在用着“页脚回调” https://datatables.net/reference/option/footerCallbackDatatables提供的功能。但是它在页脚中没有显示任何内容

数据表解释

“请注意,如果表格没有 tfoot 元素,则此回调 不会被解雇。”

所以我已将 tfoot 添加到表中,以便回调将被触发

<table id="monthlytable" class="display" cellspacing="0" width="100%">  
<thead></thead><tfoot></tfoot></table>

回调函数:

"footerCallback": function ( tfoot, data, start, end, display ) {
var api = this.api(), data;

// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
    i.replace(/[\$,]/g, '')*1 :
    typeof i === 'number' ?
    i : 0;
};

// Total over all pages
total = api
  .column( 3 )
  .data()
  .reduce( function (a, b) {
        return intVal(a) + intVal(b);
    }, 0 );

// Update footer
var numFormat = $.fn.dataTable.render.number( '\,', '.', 2, '£' ).display;
    $( api.column( 3 ).footer() ).html(numFormat(total));
}

我尝试过使用"headerCallback"使用与上面相同的代码(更改为显示在标题中)并且它工作得很好。

headerCallback 有效但 footerCallback 无效是否有原因?


添加这个:

buttons: [{ extend: 'print',
            footer: true }]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

数据表“footerCallback”函数未在页脚中显示结果 的相关文章

随机推荐