Created
June 23, 2014 20:54
-
-
Save maxx-coffee/34eae2e11e8a54b0d416 to your computer and use it in GitHub Desktop.
calculate table columns in javascript
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
calculate_summary = ($el) -> | |
$cells = $("td", $el) | |
$cells.each (i, v) -> | |
val = parseInt($(this).text()) | |
int = if isNaN(val) then 0 else val | |
if !sums[i]? | |
sums[i] = 0 | |
sums[i] = sums[i] + int | |
return sums | |
$ -> | |
$table = $("#daily_summary") | |
$rows = $("tr", $table) | |
window.sums = [] | |
$.each $rows, (i, v) -> | |
window.calculated_sums = calculate_summary( $(this)) | |
$lastRow = $("tr:last-child", $table) | |
calculated_sums.shift() | |
$.each calculated_sums, (i,v) -> | |
console.log "hi" | |
$lastCell = $("td:last-child", $lastRow) | |
$lastCell.after("<td>#{v}</td>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment