These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Move Table Row Up / Down

sbrof
Registered: Jul 2 2008
Posts: 19
Answered

Hi, I am relatively new to JavaScript and LifeCyle but have been working with it for a couple months now. I have successfully created a table that is editable and expandable. Users can add and delete rows as necessary.

One thing that I have not figured out how to script is the ability for a user to move a row up or down within the table. I have found information about the moveInstance() function but without a background knowledge in JavaScript I am unsure how to get the required actions to work.

My Product Information:
LiveCycle Designer, Windows
StevenD
Registered: Oct 6 2006
Posts: 368
I have been working with these two scripts in a couple of my documents. I can't remember where I got them but here they are. They use the click event.

This first one moves the table row or in my case a subform up 1. If you want to work with table rows just change every occurance of the name AccountSF to the name of the table row.

if(AccountSF.index != 0)
{
var nIndexFrom = AccountSF.index;
var nIndexTo = AccountSF.index - 1;
AccountSF.instanceManager.moveInstance(nIndexFrom, nIndexTo);
xfa.form.recalculate(1);
}

This one moves the subform down 1.

var nIndex = AccountSF.index;
if((nIndex + 1) < AccountSF.instanceManager.count)
{
var nIndexFrom = nIndex;
var nIndexTo = nIndex + 1;
AccountSF.instanceManager.moveInstance(nIndexFrom, nIndexTo);
xfa.form.recalculate(1);
}

For these scripts to work the buttons they are attached to need to reside in the subform or row they are intending on moveing up and down.

StevenD

sbrof
Registered: Jul 2 2008
Posts: 19
So this started to work but still isn't functioning the way I would like. Pardon for my denseness when it comes to scripting, maybe some more information would help to solve my problems.

Initially all my rows are names Row1, Row2.... When I use the script posted above and change the 'AccountSF' to my Row names, nothing happens.

I thought maybe the uniqueness of each name was poising the problem so I removed all the numbers from the Row names which means they became Row[0], Row[1]...

When I do this the down button for the first row works(ish) It moves down one row but if I push it again it moves the second row (now the first row) down and just those two continue to switch back and forth.

Any ideas?
StevenD
Registered: Oct 6 2006
Posts: 368
Oo this is a tricky one. The script I posted assumes that you have a table that is built with one row to start off with then more rows are added so end up having multiple instances of that one row (Row1[0], Row1[1], Row[2] etc.)

I usually maintain one table row then specify as many initial rows to start off with as I want in the Row1 Object > Binding tab > Repeat Row for Each Data Item. You can set a Minimum count and a Maximum count and an Initial count.Because most of the time I am using tables in a dynamic fashion I don't usualy design fixed tables that have data in the cells allready. A good example of a dynamic use of a table in a form is the sample dynamic interactive Purchase Order form that comes with LiveCycle Designer.

The sample file I mention doesn't do any of the table row moving like what we are talking about so I wish I could post an example here of how I do this.

StevenD

sbrof
Registered: Jul 2 2008
Posts: 19
Thanks a ton!! that second post really helped. I didn't even think to use the initial count that way but it does make a lot more sense. increasing the initial count to the number of rows I want means everything works now and my add and delete rows still work.

Fantastic!
StevenD
Registered: Oct 6 2006
Posts: 368
I wish there was a way to easily post screen captures and samples.

StevenD