Skip to content

Instantly share code, notes, and snippets.

@csalgueiro
Created October 8, 2013 06:49
Show Gist options
  • Save csalgueiro/6880568 to your computer and use it in GitHub Desktop.
Save csalgueiro/6880568 to your computer and use it in GitHub Desktop.
Sumar Totales de un Datable (siempre y cuando haya texto en el th equivalente de la anterior fila)
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
var total = [];
if(aaData.length>0){
for ( var i=0 ; i<aaData.length ; i++ ){
for ( var j=1 ; j<aaData[i].length; j++ ){
if(aaData[i][j]!="undefined" && aaData[i][j]!=null){
total[j] = (parseFloat(total[j]) || 0) + parseFloat(aaData[i][j]);
}
}
}
for ( var j=1; j<aaData[0].length; j++ ){
if($("tfoot tr:eq(0) th:eq("+(j-1)+")",packing_lineasTable).text()!=""){
$("tfoot tr:eq(1) th:eq("+(j-1)+")",packing_lineasTable).html("<strong>"+total[j]+"</strong>");
}
}
}
},
<tfoot>
<tr>
<th></th>
<th></th>
<th>Total euros</th>
<th>Total kg</th>
</tr>
<tr>
<th></th> <!-- NO pintaria nada-->
<th></th> <!-- NO pintaria nada-->
<th></th> <!-- pintaria aquí el total de euros-->
<th></th> <!-- pintaria aquí el total de kg-->
</tr>
</tfoot>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment