我在使用 jQuery DataTable fnFooterCallback 对列求和时遇到问题。例如,我在列中有值(双字段):
2.0 3.0 4.0
我在页脚单元格中得到总值:2.0 3.0 4.0 而不是 9.0 怎么了?
这是代码:
$(document).ready(function() {
$('#example').dataTable({
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
var iTotal = [0,0,0,0,0,0,0,0,0];
for ( var i=0 ; i<aaData.length ; i++ )
{
iTotal[0] += aaData[i][5];
iTotal[1] += aaData[i][6];
iTotal[2] += aaData[i][7];
iTotal[3] += aaData[i][8];
iTotal[4] += aaData[i][9];
iTotal[5] += aaData[i][10];
iTotal[6] += aaData[i][11];
iTotal[7] += aaData[i][12];
}
var nCells = nRow.getElementsByTagName('th');
nCells[5].innerHTML=iTotal[0];
nCells[6].innerHTML=iTotal[1];
nCells[7].innerHTML=iTotal[2];
nCells[8].innerHTML=iTotal[3];
nCells[9].innerHTML=iTotal[4];
nCells[10].innerHTML=iTotal[5];
nCells[11].innerHTML=iTotal[6];
nCells[12].innerHTML=iTotal[7];
}
}
);
} );
感谢您的帮助,对不起我的英语:)