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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Dynamic Table - How do I add a row above current row?

clintalba
Level 1
Level 1

I have a document index.  When I receive a new document, I add it to my index in reverse chronological order.  I want to select a button to add a new row above the selected row.

Currently, I can add a row to the bottom of my table.  I cannot get moveInstance to actually move the new line.

The Add Row button and script is:

   this.parent.parent.instanceManager.addInstance(true);
   this.parent.parent.moveInstance(1,0);

 

Here's a screenshot of the structure.  I have three dynamic tables, each with the same behavior.  I'm not a programmer but I'm working through this project with lots of tutorials.

When I select the + button, I get a new row at the bottom of the table.  I'd like it the row above it's current row.

clintalba_0-1585860096120.png

 

1 Accepted Solution
radzmar
Correct answer by
Level 10
Level 10

Hi, 

that's quite simple:

 

 

var i = this.parent.parent.index,
	j;
	
PartB._Row1.addInstance(true); // add new row
j = PartB._Row1.count - 1; // get index of last row. It's the one that was just added.
PartB._Row1.moveInstance(j, i); // move it above the current row

 

View solution in original post

3 Replies
radzmar
Correct answer by
Level 10
Level 10

Hi, 

that's quite simple:

 

 

var i = this.parent.parent.index,
	j;
	
PartB._Row1.addInstance(true); // add new row
j = PartB._Row1.count - 1; // get index of last row. It's the one that was just added.
PartB._Row1.moveInstance(j, i); // move it above the current row

 

View solution in original post

clintalba
Level 1
Level 1

1) I was formatting and designing this under the Master Pages and I think that was causing issues with the moveInstance.

2) Here's what I came up with for adding a row above after much searching and using the ideas posted here:

Code

//Add Instance Above Selected Button
var rowIndex = this.parent.parent.index; //What row is the button I just clicked on?
var rowNew = this.resolveNode('Part_B._Row1').addInstance(1); //Add new row
var rowCount = this.resolveNode('Part_B._Row1').count - 1; //How many instances do I now have? Subtract 1 to make it an index
var rowNewIndex = rowNew.index; //Where is this new instance?
_Row1.moveInstance(rowNewIndex,rowIndex); //Move the new instance above!!!!!

if (xfa.host.version < 😎 {
xfa.form.recalculate(1);
}

 

clintalba_0-1588194593874.png

 

clintalba
Level 1
Level 1
How can I make this script more efficient? I had to edit the Part_B portions when I reused it in two other subforms, but otherwise, worked great!