Friday, February 13, 2015

Columns Grand total in Table component of Pentaho CDE

Hi Guys,

Table component has no direct feature of adding column totals as of this post written date(July 2nd 2013)....

Here is the pentaho community & data tables shared java script  to find the Summation of columns in Table component.

Write below code in Draw Function of Table Component.

function f() {
    var grandTotalRow = "<tfoot><tr><td>Total</td>";
 
  for(i=1;i<4;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(2);+"</td>";
        }
          grandTotalRow += "</tr></tfoot>";
          if($(#+this.htmlObject+ tfoot).length===0)
        $(#+this.htmlObject).find(table).append(grandTotalRow);

    }



Sample output:

References :

https://www.datatables.net/forums/discussion/17132/summary-footer-row

http://forums.pentaho.com/showthread.php?94187-Table-Component-Grand-total

Example :
https://metrics.mozilla.com/data/content/pentaho-cdf-dd/Render?solution=metrics2&path=%2FgetInvolved&file=getInvolved.wcdf

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.