Skip to main content
Sunil Yadav
Legend
March 18, 2019
Question

Move rows vertically in table

  • March 18, 2019
  • 1 reply
  • 589 views

As in below screenshots, I want to move entire row vertically upward or downward accordingly.

How can I move row within the table using InDesign Javascript.

Move row after 7th row.

Thanks in Advance

Sunil

This topic has been closed for replies.

1 reply

Community Expert
March 18, 2019

Hi Sunil,

there is no DOM feature like table.row.move() or table.row.duplicate().

So I can only think of:

1. Add a new table row at the positon you want to move your row to.

2. Select and cut the row you want to move with app.select( tableRow ) and app.cut().

3. Select the new added row and paste the contents of the clipboard with app.paste().

If your source row has a fixed height you have to apply that fixed height also to the traget row.

Here some code where I suppose that there is only one story with one table in your document.

Based on your screenshot I selected the appropriate index numbers for the table rows:

// Supposed there is only one story with one table in your document:

var table = app.documents[0].stories[0].tables[0];

var tableRowToMove = table.rows[3];

app.select( tableRowToMove );

app.cut();

var newRow = table.rows.add( LocationOptions.AFTER , table.rows[6] );

app.select( newRow );

app.paste();

Before script execution:

After script execution. Note: Row of cells is selected.

Regards,
Uwe

Sunil Yadav
Legend
March 18, 2019

That was first thought in my mind.

But unfortunately InDesign Server doesn't allow select, copy, cut or paste.

That was my bad

That I am writing script for InDesign Server not Desktop version InDesign.

Thanks Again

Sunil