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

This widget could not be displayed.

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>');

});

});

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

485 views 3 18
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