-
-
Save jkubos/b1217eb456b68dce79dc to your computer and use it in GitHub Desktop.
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
<script type="text/javascript" > | |
AJS.toInit(function ($) { | |
var list = AJS.$('table.confluenceTable tbody th:contains("#sum")'); | |
list.each(function(index, item) { | |
var elem = AJS.$(item); | |
var parentRow = elem.parent(); | |
var parentTbody = parentRow.parent(); | |
var column = parentRow.find('th').index(elem); | |
var sum = 0; | |
var totalColumns = parentRow.find('th').length; | |
parentTbody.find('tr').each(function(index, row) { | |
var elem = AJS.$(row); | |
var td = elem.find('td'); | |
if (td.length > 0) { | |
var value = td.eq(column).text(); | |
var float = parseFloat(value); | |
if (!isNaN(float)) { | |
sum += float; | |
} | |
} | |
}); | |
elem.text(sum); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
empty fields does not result in NaN