Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

addinstance to middle of table in javascript

Avatar

11-10-2008

I am trying to insert a new row into the middle of a table in javascript. Adding to the end of the table is easy, but I can't seem to figure out the syntax for inserting into the middle. I'm spent hours trying to come up with something.



Since adding to the end of the table is:



Table1._detail.addinstance(1)



It would be nice if I could using something like:



Table1.detail[5].addinstance(1)



thanks,

Replies

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

12-10-2008

That syntax is correct but if you are trying to add to the middle of the table then detail[5] probably already exisits.



What if you added a new row to the end of the table then used the moveInstance method to reposition it where you want. It is documented on the scripting reference.

Avatar

Avatar
Level 1
James_S__Dennis
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
James_S__Dennis
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
View profile
James_S__Dennis
Level 1

03-05-2009

I've been looking around for a solution myself, and have combined a few different methods and managed to work it out using a form variable and insertInstance() to insert a table row above the table row with current focus. I chose this method as I only wanted the one button on the form due to space limitations instead on having a button on each row, like with the 'Delete' row example on the Purchase Order sample.

Step 1 - Create a form Variable {File:Form Properties:Variables}, lets say 'nIndex' and assign it any number.

Step 2 - I added the following Javascript to the first row/ first column of my table on the 'Enter' event:

              

     var xxx = this.parent.index;

     nIndex.value = String(xxx);

If necessary this could be repeated for each row in the table.

Step 3 - I added a button to the form, basically anywhere will do, called lets say 'Insert Above' with the following Javascript on 'Click' event:

    {table_name}._{row_name}.insertInstance(nIndex.value);

The '_' following the first period(.) is required.

Information:

I am using my form to document User Acceptance Test Script steps and needed the capability for the user to insert new steps as the script is being developed.

I also have another button 'Add Steps' which uses addInstance() to allow the user add rows to the bottom of the table for new steps.

NB: The same logic works for removeInstance to delete the row in the table with current focus.