我正在尝试对jquery数据表中的列进行总计,但表页脚未出现
总计出现在控制台中,并且总计在过滤器或搜索中发生了变化。
但是表在初始化后没有页脚标记
我不确定表初始化是否在footerCallback之前调用
该表工作正常,并且计算了总数,但是我认为这一切都发生在表初始化之前。这是正确的
如果我正确,则需要进行哪些更改?
var table = $('#resultstable').DataTable(
{
fixedHeader: {
footer: true,
footerOffset: 40
},
"paging": false,
"info":false,
"stateSaving":true,
"searching":true,
"order": [[ 1, "asc" ]],
data:tabledata,
columnsDef:[
{
"targets":[2],
ClassName:"sum"
}],
columns:[
{
className:'details-control',
orderable:false,
data:null,
defaultContent: '',
},
{
orderable:true,
className:"packName",
title:"Name : "
},
{
className:'sum',
orderable:true,
title:"Total : ",
},
{
className:'sum',
title:"Passed : ",
orderable:true,
},
{
className:'sum',
title:"Failed ",
orderable:true,
},
{
className:'sum',
title:"New Failures ",
'orderable':true
}
],
"fnCreatedRow": function( nRow, aData, iDataIndex )
{
$(nRow).attr('value', aData[(aData.length-1)]);
},
"initComplete": function(settings, json)
{
},
"footerCallback":function(row, data, start, end,display)
{
var api = this.api();
var cols = api.columns('.sum',{search:'applied'});
cols.every(function(){
var sum = this
.data()
.reduce(function(a,b){
var x = parseFloat(a) || 0;
var y = parseFloat(b) || 0;
return x + y;
},0);
console.log(sum);
$(this.footer()).html(sum);
});
}
} );