Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Growable table row and instantly summing contents in the footer row.

Avatar

Former Community Member

I have a table with Header, Footer and Single Row, the row is designed in such a way that when a [Add_Row] button is clicked it added a new row (row2, row3 , etc ....). I can manager that far.  But after filling up the first row with contents [number] and clicking add_row button i want row2 added with all the contents of row1 appear on row 2 by default. (and not blank row2 appears). Not only that the sum of row 1 & row2 instantly appear on Footer row, after adding the row two. How do i achieve this?

(it is with LC Designer ES1 or simply ES I am using).

9 Replies

Avatar

Level 7

It depends on where your button is placed and how you have coded it. If, for instance, your button is on the last cell in Row1 and the code to add another row is something like (in formcalc):

Row1.instanceManager.addInstance()

Then to copy the data from the initial row to the next row you could put in the click event of the button under the addInstance code (in formcalc):

Row1[$.parent.index + 1].Cell1 = Row1[$.parent.index].Cell1

and then just change Cell1 to whatever you have called each cell in the row.

For the sum at the end just put in the footer cell in the calculate event (in formcalc):

$ = sum(Row1[*].Cell1)

Avatar

Former Community Member

Structure of the form is like this The tables a above the add_button,  the script i am not sure may be java or formcalc,  the add button is outside the table beneath the footer row. I will try your suggestion when i get back home. Thanks for the tips.

Avatar

Former Community Member

You suggestion

  Row1.instanceManager.addInstance()

  Row1[$.parent.index + 1].Cell1 = Row1[$.parent.index].Cell1

work only upto the second row. After filling up the first row i click the add_row button and it can copy the first raw values.

again, after this instance when add_row was clicked a new row 3rd row appears with blank values.

I want values in the preceeding copied to the next row  for each and every rows aded.

Avatar

Level 7

As I said above that code will only work if the button is actually in the row. If you have the button outside the table then using '$' won't work. You could use a variable instead that would act as the index, so say set a form variable called 'rowIndex' and set the initial value to 0. Then the code (in formcalc) for your button would be something like:

Table2.Row1.instanceManager.addInstance()

Table2.Row1[rowIndex + 1].Cell2 = Table2.Row1[rowIndex].Cell2

rowIndex = rowIndex + 1

Avatar

Former Community Member

Thanks for the reply again, i will try when i get back home.

By the way as you suggested

Row1.instanceManager.addInstance()  // this work only when Row1.InstanceManager.addInstance(1 or 0)  but when left blank it won't work.

Then to copy the data from the initial row to the next row you could put in the click event of the button under the addInstance code (in formcalc):

Row1[$.parent.index + 1].Cell1 = Row1[$.parent.index].Cell1

and then just change Cell1 to whatever you have called each cell in the row.

For the sum at the end just put in the footer cell in the calculate event (in formcalc):

$ = sum(Row1[*].Cell1)

Avatar

Former Community Member

I tried this loop sequence it did not help

var nItems= form1.sheet1.Table1.Row1.instanceManager.count;

for ( x=0; x <nItems; x++)

{form1.sheet1.Table1.Row1[x+1].Cell2 = form1.sheet1.Table1.Row1[x].Cell2;

............................................... .Cell3 = .......................................... .Cell3;

}

Avatar

Level 7

that for loop is in javascript. The code I gave you is formcalc - you can't use both in the same event so you need to choose one language for the button code and stick with it.

Avatar

Former Community Member

when i write the code in FormCalc there is erorer in the

either in this

for (for  x=0; x <nItems; x++)

form1.sheet1.Table1.Row1[x+1].Cell2 = form1.sheet1.Table1.Row1[x].Cell2;

or

for (x=0, x <nItems)

form1.sheet1.Table1.Row1[x+1].Cell2 = form1.sheet1.Table1.Row1[x].Cell2;

x=x+1

Why ????

Avatar

Former Community Member

the form can be had at http://www.adrive.com/public/xqy7t3/Arrer Pay Calculator V5.0.0.1(final1).pdf will there be any solution ?