Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Move rows vertically in table

Advocate ,
Mar 18, 2019 Mar 18, 2019

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.

row1.JPG

Move row after 7th row.

row2.JPG

Thanks in Advance

Sunil

TOPICS
Scripting
626
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 18, 2019 Mar 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:

1-BEFORE-MoveTableRow.PNG

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

2-AFTER-MoveTableRow.PNG

Regards,
Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 18, 2019 Mar 18, 2019
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines