Inserting a Table Template

I have inserted a table template into a free text field using JEditor. Users will enter numbers across each row. Is there a way to total the numbers in the last column?

2 answers

Hi Cindy,

Thank you for your interest in JEditor.

This is possible with JEditor 1.5.45. You need to add some javascript in JEditor Configuration > Custom Javascript.

I'll provide a simple example of this function. Create new template using sample html code and add sample javascript code to custom javascript in JEditor Configuration.

You can use this sample as basis for your solution. Please feel free to contact our support if you need any help with developing your macro.

Sample HTML code

<table border="1" cellpadding="1" cellspacing="1" class="sum" style="width: 500px; border-collapse: collapse; ">

<thead>

<tr>

<th>

Value 1</th>

<th>

Value 2</th>

</tr>

</thead>

<tbody>

<tr>

<td>

15432</td>

<td>

4324</td>

</tr>

<tr>

<td>

42343</td>

<td>

234324</td>

</tr>

<tr>

<td>

123</td>

<td>

2343</td>

</tr>

</tbody>

</table>

Sample javascript code

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function ()

{

AJS.$('table.sum tbody tr').each(function() {

var numbers = AJS.$('td:not(".total")', this),

total = 0;

numbers.each(function() {

total+= parseInt( AJS.$(this).text(), 10);

});

if (AJS.$(this).find('td.total').length == 0) AJS.$(this).append('<td class="total"><b>'+total+'</b></td>');

});

});

AJS.$(function(){

AJS.$('table.sum tbody tr').each(function() {

var numbers = AJS.$('td:not(".total")', this),

total = 0;

numbers.each(function() {

total+= parseInt( AJS.$(this).text(), 10);

});

if (AJS.$(this).find('td.total').length == 0) AJS.$(this).append('<td class="total"><b>'+total+'</b></td>');

});

});

Thank you for your suggestion. I tries it out and it did not work exactly the way that I needed it to work. I have found an alternative solution. Thank you again.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

108 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you