Expand my Community achievements bar.

SOLVED

Button to delete CURRENT row of a table

Avatar

Level 2

This test document has a table which mostly works like I want, but the delete row buttons always delete the second row regardless of which row's delete button is clicked. The code is:

How do I modify this so that if you click the delete button on row 5 (for example), it deletes row 5, not row 2. Now it always deletes row 2, no matter which button is clicked.

Also, after I row is deleted, how I can I get the rows to re-number automatically? The code for auto numbering is:

I had tried using this code:

for autonumbering (per this blog entry by BR001), but I could never get it to work on my table, although it works great in his example. In BR001's example, he has one delete button per row and it always deletes only the row that it's on and it always renumbers automatically. I'd like to use his method, but I've spent hours trying to figure out where I'm failing to follow his example.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

ok, your script always will delete the 2. instance as removeInstance(1) simply means to delete instance 1.

You have to keep in mind that all nodes have index numbers starting with 0.

So the first instance of Row1 is adressed with Row[0], the second with Row[1] ... the tenth with Row[9].

To delete the current instance you can use the delete button as reference point.

From this reference point you're going upwards in the node tree to find the desired row.


Table1.Row1.instanceManager.removeInstance(this.parent.parent.index);


this = the current object i.e. Button2

parent = the parent of Button2 which is Subform1

parent = the parent of Subform1 which is Row1

index = the instance number of the current row

Ok, to keep the row numbers up to date you should use the indexChange event of your row (just add it after you existing row shading script).


simple2.rawValue = this.index + 1;


View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

ok, your script always will delete the 2. instance as removeInstance(1) simply means to delete instance 1.

You have to keep in mind that all nodes have index numbers starting with 0.

So the first instance of Row1 is adressed with Row[0], the second with Row[1] ... the tenth with Row[9].

To delete the current instance you can use the delete button as reference point.

From this reference point you're going upwards in the node tree to find the desired row.


Table1.Row1.instanceManager.removeInstance(this.parent.parent.index);


this = the current object i.e. Button2

parent = the parent of Button2 which is Subform1

parent = the parent of Subform1 which is Row1

index = the instance number of the current row

Ok, to keep the row numbers up to date you should use the indexChange event of your row (just add it after you existing row shading script).


simple2.rawValue = this.index + 1;