在jQuery数据表中使用fnFooterCallback添加第二个总计行

在jQuery数据表中使用fnFooterCallback添加第二个总计行,jquery,mysql,datatables,Jquery,Mysql,Datatables,我有以下页脚表: <tfoot> <tr> <th colspan="9">Total amount:</th> <th></th> <th></th> </tr> <tr> <th colspan="9">Grand total:</th> &l

我有以下页脚表:

<tfoot>
    <tr>
        <th colspan="9">Total amount:</th> 
        <th></th>
        <th></th>
    </tr>
    <tr>
        <th colspan="9">Grand total:</th> 
        <th colspan="2"></th>
    </tr>                                    
</tfoot>  
在第二个页脚行中,我想插入总额和SAmount之间的差额。 如何在第二行页脚插入差异合计行?

我自己找到的

var secondRow = $(nRow).next()[0]; 
var nCells = secondRow.getElementsByTagName('td'); 

谢谢你提供的信息。如果要将第三个页脚行添加到datatable,则可以使用以下命令:

var thirdRow=$$nRow.next[0]。next[0];
var nCells=thirdRow.getElementsByTagName'th'

如果您想使用插件导出,它将只导出页脚的第一行,要解决此问题,您可以修改dataTables.tablettools.js中的函数_fngedatatabledata,使用以下新代码更改页脚部分:

if (oConfig.bFooter && dt.nTFoot !== null) {
    aRow = [];
    for (i = 0, iLen = dt.nTFoot.childElementCount; i < iLen; i++) {
        for (j = 0, jLen = dt.nTFoot.children[i].childElementCount; j < jLen; j++) {
            sLoopData = dt.nTFoot.children[i].cells[j].innerHTML.replace(/\n/g, " ").replace(/<.*?>/g, "");
            sLoopData = this._fnHtmlDecode(sLoopData);
            aRow.push(this._fnBoundData(sLoopData, oConfig.sFieldBoundary, regex));
        }
        aData.push(aRow.join(oConfig.sFieldSeperator));
        aRow = [];
    }
}

Ernesto Ramos的答案将抛出错误,如果表尾中有任何colspans是的,我知道datatables不支持colspans。Tabletools通过清除数据来处理错误,因此文件完全为空

下面的解决方案与上面的非常类似,但允许使用colspans

if (oConfig.bFooter && dt.nTFoot !== null) {
    var numRows = dt.nTFoot.rows.length;

    for (j = 0; j < numRows; j++) {
        aRow = [];
        for (i = 0, iLen = dt.aoColumns.length ; i < iLen ; i++) {
            if (aColumnsInc[i] && dt.nTFoot.rows[j].cells[i] && dt.aoColumns[i].nTf !== null) {
                sLoopData = dt.nTFoot.rows[j].cells[i].innerHTML.replace(/\n/g, " ").replace(/<.*?>/g, "");
                sLoopData = this._fnHtmlDecode(sLoopData);
                aRow.push(this._fnBoundData(sLoopData, oConfig.sFieldBoundary, regex));
            }
        }

        aData.push(aRow.join(oConfig.sFieldSeperator));
    }
}

我自己找到的var secondRow=$nRow.next[0];var nCells=secondRow.getElementsByTagName'td';这并不能回答这个问题。OP只询问如何添加第二行。因此,你的答案应该是对相应答案的评论,而不是答案。你可以随时对自己的帖子发表评论,一旦你有足够的评论,你就可以发表评论了。
if (oConfig.bFooter && dt.nTFoot !== null) {
    var numRows = dt.nTFoot.rows.length;

    for (j = 0; j < numRows; j++) {
        aRow = [];
        for (i = 0, iLen = dt.aoColumns.length ; i < iLen ; i++) {
            if (aColumnsInc[i] && dt.nTFoot.rows[j].cells[i] && dt.aoColumns[i].nTf !== null) {
                sLoopData = dt.nTFoot.rows[j].cells[i].innerHTML.replace(/\n/g, " ").replace(/<.*?>/g, "");
                sLoopData = this._fnHtmlDecode(sLoopData);
                aRow.push(this._fnBoundData(sLoopData, oConfig.sFieldBoundary, regex));
            }
        }

        aData.push(aRow.join(oConfig.sFieldSeperator));
    }
}