Inserting a Table Template

Cindy Creswick September 9, 2013

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

0 votes
Cindy Creswick September 23, 2013

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.

0 votes
Kirill Bobrovskikh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2013

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

});

});

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events