DataTable的fnFooterCallback说明 [英] Explanation of fnFooterCallback for DataTables

查看:1661
本文介绍了DataTable的fnFooterCallback说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用通过调用Neo4j数据库加载的aaData数组来创建表。我想做一个页脚行,总结其他行中的数据,我发现fnFooterCallback,但我不明白他们如何使用它。这是我在DataTables网站上找到的例子。

I am creating a table by using the aaData array that is being loaded by a call to a Neo4j Database. I would like to make a footer row that sums up data in the other rows and I found the fnFooterCallback but I don't understand how they used it. This is the example I found on the DataTables website

$(document).ready( function() { 
    $('#example').dataTable( {
        "fnFooterCallback": function( nFoot, aData, iStart, iEnd, aiDisplay ) {
            nFoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+iStart;
        }
    } );
} )


$ b $我知道我把aaData数组放在哪里,说aData,但是我不知道其他四个参数来自哪里。我是新的数据表,在文档中找不到任何东西来解释它,除了代表数组,n代表节点,i代表整数。

I know i put the aaData array where is says aData, but I have no clue where the other four parameters come from. I'm new to datatables and can't find anything in the documentation to explain it other than a stands for array, n for node, and i for integer.

我的表不是什么小说。第一列是解释行中的内容的文本,其余的列包含整数。我只想要一个在第一列中显示总计的页脚,然后显示所有其他列的总和

My table is nothing novel. The first column is text explaining what's in the row and the remaining columns contain integers. I simply want a footer that says total in the first column and then displays the sums for all the other columns

推荐答案

它适用于方式:

当绘制表时,当它绘制页脚时,它将执行您定义的函数。
在你的例子中,它只是用提供的文本替换页脚的第一个单元格。

When it draw the table, when it is drawing the footer, it will execute the function you defined. In your example, it just replace the first cell of the footer with the text supplied.

这是另一个例子:

function( nRow, aaData, iStart, iEnd, aiDisplay ) {
        /* Calculate sums of page shown */
        var iPageMargem = 0;
        var iPageClient = 0;
        var iPageMaximo = aaData[ aiDisplay[iStart] ][5]*1;
        var i;
        for ( i=iStart ; i<iEnd ; i++ ) {
            iPageMargem += aaData[ aiDisplay[i] ][2]*1;
            iPageClient += aaData[ aiDisplay[i] ][3]*1;
            if (aaData[ aiDisplay[i] ][5]*1 > iPageMaximo) {
                iPageMaximo = aaData[ aiDisplay[i] ][5]*1;
            };
        }                       
        var nCells = nRow.getElementsByTagName('td');
        nCells[2].innerHTML = $.jqplot.sprintf("%'.2f",iPageMargem);
        nCells[3].innerHTML = $.jqplot.sprintf("%'.0f",iPageClient);
        nCells[4].innerHTML = $.jqplot.sprintf("%'.2f",iPageMargem/iPageClient);
        nCells[5].innerHTML = $.jqplot.sprintf("%'.2f",iPageMaximo);
        iPageMargem=null;
        iPageClient=null;
        iPageMaximo=null;
        i=null;
        nCells=null;
    };

数据如下:

["Tipo","Segmento","Margem","Clientes","Média","Máximo"],
["PF","Exclusivo",137066708.81,263220,520.73,119718.04],
["RR","Representante Governos",5776837.90,30257,190.93,35185.36],
["PJ","Investidores Institucionais Privados",280488.03,40,7012.20,236619.62],
["","Total","","","",""]

它将计算第三列和第四列的总和以及第五列的最大值,但仅显示当前页。然后它将用这些值替换页脚。

It will calculate the sum of the third and fourth column and the maximum of fifth column, but only of the current page shown. Then It will replace the footer with these values.

这篇关于DataTable的fnFooterCallback说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆