Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

insert a row in between rows

Avatar

Level 2

Is there a way to add a row in between rows?

1 Accepted Solution

Avatar

Correct answer by
Level 1

Hello Vic,

yes there is.

Place a button within your table and add the following Javascript code to its click event:

var currentRepeatable = this.parent;

var im = currentRepeatable.instanceManager;

var newRepeatable = im.addInstance(1);

im.moveInstance(newRepeatable.index, this.parent.index);

You might have to replace "this.parent" in line 1 with another SOM-Expression referring to your repeatable row containing your button.

Currently the new instance is inserted in front of the row containing the button. If you want to insert after the current row change the last line to:

im.moveInstance(newRepeatable.index, this.parent.index + 1);

Hope that helps,

Martin

View solution in original post

13 Replies

Avatar

Level 2

Do you still need help with this question? If so, I'm assuming you have created a table and an add button to add a new row of cells and that your problem is the row is added at the bottom of the table.

I know how to get this done but it is only something I would describe on video. Let me know if you still need help and I will upload a quick video to youtube or my website. My way of doing it is a bit annoying but it gets the job done (and its the only way I could figure out how to do it).

Andrew

Avatar

Level 2

Yes, please! I still need help!

Thanks!

Avatar

Level 5

One question.

  1. You have an static table?
  2. Or you have a dynamic table and want to insert a row when you click a button but you want not to insert upstream. You want to insert above?

Avatar

Level 2

I have a dynamic table and want to insert in between to rows.

Avatar

Level 5

You can use a button? When not when the rows should be insert?

Avatar

Level 2

yes, you can use a button and can be inserted anytime.

Avatar

Level 2

So watch this  15 sec video on YouTube. I believe this is what you are looking to accomplish. I just want to be clear before wasting time (both of ours). If it is then I will do a full video on how to accomplish it. You likely have set everything up in a table. The only way I could figure out how to make it work this way is to take everything out of the table. You'll see what I mean.

Let me know and I will try to do something this weekend

http://youtu.be/A_yLRzOpWto 

Avatar

Level 2

Yes! Yes! That's what I'm looking for!

Thanks.

Avatar

Correct answer by
Level 1

Hello Vic,

yes there is.

Place a button within your table and add the following Javascript code to its click event:

var currentRepeatable = this.parent;

var im = currentRepeatable.instanceManager;

var newRepeatable = im.addInstance(1);

im.moveInstance(newRepeatable.index, this.parent.index);

You might have to replace "this.parent" in line 1 with another SOM-Expression referring to your repeatable row containing your button.

Currently the new instance is inserted in front of the row containing the button. If you want to insert after the current row change the last line to:

im.moveInstance(newRepeatable.index, this.parent.index + 1);

Hope that helps,

Martin

Avatar

Level 2

Martin,

This worked great! This is what I needed! Thanks for the help!

Avatar

Level 1

I tried pasting on the code as mentioned above but my rows are still inserting from the bottom. Can you please help?

Avatar

Level 2

var currentRepeatable = this.parent;
var im = currentRepeatable.instanceManager;
var newRepeatable = im.addInstance(1);
im.moveInstance(newRepeatable.index, this.parent.index);

xfa.form.recalculate(true);

Avatar

Level 1

Vic,

Thanks, I pasted the code into my "add" button, however the rows are still inserting from the bottom.