jQuery数据表页脚,包含来自ajax输出的总行数

jQuery数据表页脚,包含来自ajax输出的总行数,jquery,datatables,Jquery,Datatables,我试图使用fnFooterCallback将一列中的金额相加为总数,我还不能计算出的部分是,我需要该页面的总数,我从aaData中得到了很好的结果 您知道如何使用ajax输出在aaData中获得的输出来显示页脚吗?不确定这是否是您想要的,但我试一试 要在页脚中显示,请将此代码放在和 总数: 因此它可以显示在页脚中 然后将其添加到启动中: "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) { /

我试图使用fnFooterCallback将一列中的金额相加为总数,我还不能计算出的部分是,我需要该页面的总数,我从aaData中得到了很好的结果


您知道如何使用ajax输出在aaData中获得的输出来显示页脚吗?

不确定这是否是您想要的,但我试一试

要在页脚中显示,请将此代码放在


总数:
因此它可以显示在页脚中

然后将其添加到启动中:

"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
    /*
     * Calculate the total market share for all browsers in this table (ie inc. outside
     * the pagination)
     */
    var iTotalMarket = 0;
    for ( var i=0 ; i<aaData.length ; i++ )
    {
        iTotalMarket += aaData[i][1]*1;
    }

    /* Calculate the market share for browsers on this page */
    var iPageMarket = 0;
    for ( var i=iStart ; i<iEnd ; i++ )
    {
        iPageMarket += aaData[ aiDisplay[i] ][1]*1;
    }

    /* Modify the footer row to match what we want */
    var nCells = nRow.getElementsByTagName('th');
    nCells[1].innerHTML = parseInt(iPageMarket);
}
“fnFooterCallback”:函数(nRow、aaData、iStart、iEnd、aiDisplay){
/*
*计算此表中所有浏览器的总市场份额(即外部浏览器)
*(分页)
*/
var-iTotalMarket=0;

对于(var i=0;i而言,此代码同样有效,并且更易于使用和理解:

将此添加到刀片视图:

<tfoot>
   <tr>
       <th>Total:</th> 
       <th></th>
   </tr>
</tfoot>
此代码需要放在

table.dataTable({

我希望这能有所帮助。

正在寻找相同的。如果您找到了,请(通过回答您的问题)让我知道。谢谢。到目前为止,这对我很有用。:)谢谢!我必须更新ajaxed datatable的页脚。我返回了一个json对象,其中包含几个字段。我使用了您的解决方案作为基础。不知道如何访问该特定字段“total sum json object”是我在“fnFooterCallback”中从ajax返回的,所以我修改了jquery.datatable.js以管理将其分配给全局变量并在这个回调中使用。再次感谢您!:)当我尝试此操作时,nRow未定义,它当然会崩溃。
"footerCallback": function ( row, data, start, end, display ) {
                        var api = this.api(), data;


                        var intVal = function ( i ) {
                            return typeof i === 'string' ?
                                i.replace(/[\$,]/g, '')*1 :
                                typeof i === 'number' ?
                                    i : 0;
                        };

                        // This is for the Total text
                        var col0 = api
                            .column( 0 )
                            .data()
                            .reduce( function (a, b) {
                                return intVal(a) + intVal(b);
                            }, 0 ); 
                    //First, please note var name col1 and we use it then
                    var col1 = api
                        .column( 1 )
                        .data()
                        .reduce( function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0 );

                    $( api.column( 0 ).footer() ).html('Total');
                    // Here you can add the rows
                    $( api.column( 1 ).footer() ).html(col1); 
                    },
table.dataTable({