table 总计分页

Grand Total in the table with pagination

我对 Pentaho CDE 有疑问。 我想向 table 组件添加一行,总计为数字列,但我发现的代码仅适用于 table 的一页。当我将分页设置为 True 时,只计算第一页的总计。 我想在不依赖页数的情况下为所有行获取一个值。

代码如下:

function f() {
    var grandTotalRow = "<tfoot><tr><td>Suma</td>";

  for(i=1;i<2;i++) {
        var total=0;
         var rows = $('#' + this.htmlObject + ' tbody tr');

          rows.each(function() {
            var cellVal = parseFloat($('td:eq('+i+')', this).text().replace(',',''));

          if(!isNaN(cellVal)){
              total+=cellVal;
          }

           });
        grandTotalRow += "<td>"+total.toFixed(0);+"</td>";
        }
          grandTotalRow += "</tr></tfoot>";
          if($('#'+this.htmlObject+' tfoot').length===0)
        $('#'+this.htmlObject).find('table').append(grandTotalRow);

    }  

(来源:http://biwithui.blogspot.com/2014/06/grand-total-in-table-component.html

我将不胜感激所有的建议!

在 table 组件中处理总计的另一种方法是在 PostFetch 函数中将总计行添加到结果集中。但是总计只会在最后一页可见,使用此方法排序应该处于非活动状态。

function f(d) {
 d.queryInfo.totalRows = d.resultset.length+1 + "";
 var total = new Array("Total",0,0,0,0,0,0,0,0," ");
 d.resultset.forEach(function (row){
    row.forEach(function (c,i){
        if (i!==0 && i!==9){
            total[i] = total[i]+c;
        }
    });
 });
 d.resultset.push(total);
 return d;
} 

您可以通过将 CSS class 应用到最后一行来在 PostExecution 函数中格式化此总计行。

function f() {
  if ($('#'+this.htmlObject+'Table tr:last td:first-child').text() == 'Total') {
    $('#'+this.htmlObject+'Table tr:last').attr("class","tableTot");
  }
}