Skip to content

Instantly share code, notes, and snippets.

@timaschew
Last active November 19, 2016 15:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timaschew/6334345 to your computer and use it in GitHub Desktop.
Save timaschew/6334345 to your computer and use it in GitHub Desktop.
confluence table sum addon
<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);
sum += float;
}
});
elem.text(sum);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment