Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Delete rows from an expanding table

Avatar

Level 5

Hello,

I have an expanding table that allows users to click a "+" button in the row to add more rows.  The table contains required fields.  There is a radio button in another part of the form that if set to "No", the whole section containing the table is hidden.  I need to delete any extra rows the user may have added to the table before selecting that "No" answer, leaving only the first three rows (2 title rows and the first data row).  So if the table had six names entered (total of 8 rows) I want it to delete 7 rows; I remove the value from the first row separately.  I tried something like this, but I couldn't make it work; I'm not a very experienced scripter.  Thanks.


for (var oLen = Table1.nodes.length; oLen>3; t++) {

Table1.parent.parent.instanceManager.removeInstance(oLen);

}



1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi there,

There is an error in your for statement.

You are starting at the last instance of the row and you want to delete any rows starting from the last down to the 3rd row...

You must change your value when you are deleting 1 row, but instead of changing the oLen value you are changing the variable "t"

Also if you are starting at the last instance, and going down to the third row, you will want to decrease the index you are using instead of increasing it...

So you're code need some minor changes, and it should look like this:

Hope this help!

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi there,

There is an error in your for statement.

You are starting at the last instance of the row and you want to delete any rows starting from the last down to the 3rd row...

You must change your value when you are deleting 1 row, but instead of changing the oLen value you are changing the variable "t"

Also if you are starting at the last instance, and going down to the third row, you will want to decrease the index you are using instead of increasing it...

So you're code need some minor changes, and it should look like this:

Hope this help!

Avatar

Level 5

That did the trick, thanks!  (of course, I hadn't noticed that I forgot to change the "t" for my own counter)