Skip to main content

reorderRows

Applicable only on auto-layout frames with layoutMode set to "GRID". Moves one or more rows to a new position in the grid, shifting other rows as needed.

Signature

reorderRows(options: GridTrackReorderOptions): ReadonlyArray<GridTrackReorderEntry>

Remarks

If a child in one of the selected rows spans multiple rows, all of those spanned rows are automatically included in the move. The returned array describes both the input tracks and any tracks that were added implicitly due to spanning.

All values in fromIndices must be in the range [0, gridRowCount) and insertionIndex must be in the range [0, gridRowCount], otherwise an error will be thrown. If an error is thrown, the grid is left unchanged.

Moving the first row to the end of the grid
const grid = figma.createFrame()
grid.layoutMode = 'GRID'
grid.gridRowCount = 3
grid.gridColumnCount = 2

// Populate the grid
for (let i = 0; i < 6; i++) {
grid.appendChild(figma.createFrame())
}
// Before:
// + --- + --- +
// | 1 | 2 | <- row 0
// + --- + --- +
// | 3 | 4 | <- row 1
// + --- + --- +
// | 5 | 6 | <- row 2
// + --- + --- +

const moves = grid.reorderRows({ fromIndices: [0], insertionIndex: 3 })
// After:
// + --- + --- +
// | 3 | 4 |
// + --- + --- +
// | 5 | 6 |
// + --- + --- +
// | 1 | 2 |
// + --- + --- +
// moves => [{ from: 0, to: 2 }, { from: 1, to: 0 }, { from: 2, to: 1 }]