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.
SOLVED

Get Row index from a Dynamic Table

Avatar

Level 2

Hello Gurus,

How can I get the index of a row when it is added dynamically.

Capture.PNG

When user clicks on the "-" button he should get the index of the row on which he has clicked the button.

I have tried it using the code

var var1 = (data.Design_page1.Working_times_subform.Working_Table.Row1.instanceManager.count-1);

But it gives me the total row count.I want the index of the particular row.

Thanks.

Regards,

Nikhil

1 Accepted Solution

Avatar

Correct answer by
Level 10

On the "-" button use this.parent.parent.index to get the index of the row the button is in. the "parent" reference is used to move back up the hierarchy so if you had say a subform around the button in the cell you'd have to add another parent to find Row1.

So to delete the row try: _Row1.removeInstance(this.parent.parent.index);

Or this should work too: _Row1.removeInstance(Row1.index);

The underscore is a shortcut to the Instance Manager. You may want to avoid using it in object names, I'm pretty sure it's caused me problems in the past, I only use camel case for object names now (avoid dashes too).

You don't need to specify the entire path to the object you're trying to access. The "-" button being below Row1 can see Row1.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

On the "-" button use this.parent.parent.index to get the index of the row the button is in. the "parent" reference is used to move back up the hierarchy so if you had say a subform around the button in the cell you'd have to add another parent to find Row1.

So to delete the row try: _Row1.removeInstance(this.parent.parent.index);

Or this should work too: _Row1.removeInstance(Row1.index);

The underscore is a shortcut to the Instance Manager. You may want to avoid using it in object names, I'm pretty sure it's caused me problems in the past, I only use camel case for object names now (avoid dashes too).

You don't need to specify the entire path to the object you're trying to access. The "-" button being below Row1 can see Row1.

Avatar

Level 2

Hi Jono,

Thanks for the help.This is excatly what I was searching for.

Also thanks for the insighful suggestions.I wil suerly try and avoid using underscores and dashes.

Thanks.

Regards,

Nikhil