setGridChildPosition
Applicable only on direct children of 'GRID' auto-layout frames. Sets the position of the node
Supported on:
Signature
setGridChildPosition(rowIndex: number, columnIndex: number): void
Remarks
This method sets the position of the node within the grid based on the specified row and column indices. The row and column indices are 0-based, where 0 is the top row in the grid, and 0 is the left-most column in the grid. If the specified row or column index is out of bounds, it will throw an error. If the specified row or column index is occupied by another node, it will throw an error.
Setting the position of a node in a grid
const grid = figma.createFrame()
grid.layoutMode = 'GRID'
grid.gridRowCount = 3
grid.gridColumnCount = 3
const child1 = figma.createFrame()
const child2 = figma.createFrame()
const child2 = figma.createFrame()
// + --- + --- + --- +
// | 1 | 2 | 3 |
// + --- + --- + --- +
// | | | |
// + --- + --- + --- +
// | | | |
// + --- + --- + --- +
// If calling `appendChild` instead of [`appendChildAt`](/api/properties/nodes-appendchildat.md), nodes will be added to the first available position in the grid.
grid.appendChild(child1)
grid.appendChild(child2)
grid.appendChild(child3)
// Move the children to specific grid positions
child2.setGridPosition(1, 0)
child3.setGridPosition(2, 1)
// + --- + --- + --- +
// | 1 | | |
// + --- + --- + --- +
// | 2 | | |
// + --- + --- + --- +
// | | 3 | |
// + --- + --- + --- +