Last active
August 29, 2015 13:56
-
-
Save stevelippert/8850646 to your computer and use it in GitHub Desktop.
DataTables fnFooterCallback with Multiple footer rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) { | |
var totalPE = 0; | |
var totalPP = 0; | |
var weightedPE = 0; | |
var weightedPP = 0; | |
var seg1PE = 0; | |
var seg1PP = 0; | |
var seg1WPE = 0; | |
var seg1WPP = 0; | |
var seg2PE = 0; | |
var seg2PP = 0; | |
var seg2WPE = 0; | |
var seg2WPP = 0; | |
for ( var i=0; i<aaData.length; i++){ | |
totalPE += aaData[i][5]*1; | |
totalPP += aaData[i][6]*1; | |
weightedPE += aaData[i][7]*1; | |
weightedPP += aaData[i][8]*1; | |
if (aaData[i][3] == 1){ | |
seg1PE += aaData[i][5]*1; | |
seg1PP += aaData[i][6]*1; | |
seg1WPE += aaData[i][7]*1; | |
seg1WPP += aaData[i][8]*1; | |
}else if(aaData[i][3] == 2){ | |
seg2PE += aaData[i][5]*1; | |
seg2PP += aaData[i][6]*1; | |
seg2WPE += aaData[i][7]*1; | |
seg2WPP += aaData[i][8]*1; | |
} | |
} | |
$("#total th:nth-child(2)").text(totalPE.toFixed(2)); | |
$("#seg1Total th:nth-child(2)").text(seg1PE.toFixed(2)); | |
$("#seg2Total th:nth-child(2)").text(seg2PE.toFixed(2)); | |
$("#total th:nth-child(3)").text(totalPP.toFixed(2)); | |
$("#seg1Total th:nth-child(3)").text(seg1PP.toFixed(2)); | |
$("#seg2Total th:nth-child(3)").text(seg2PP.toFixed(2)); | |
$("#total th:nth-child(4)").text(weightedPE.toFixed(2)); | |
$("#seg1Total th:nth-child(4)").text(seg1WPE.toFixed(2)); | |
$("#seg2Total th:nth-child(4)").text(seg2WPE.toFixed(2)); | |
$("#total th:nth-child(5)").text(weightedPP.toFixed(2)); | |
$("#seg1Total th:nth-child(5)").text(seg1WPP.toFixed(2)); | |
$("#seg2Total th:nth-child(5)").text(seg2WPP.toFixed(2)); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment