Skip to content
Grid LayoutExamples

Arrange widgets and restore per-column layouts

comins-grid-layout@0.3.0React

Compare auto arrangement, row width filling, targeted expansion, and switching between 6 and 12 columns.

Reset before each comparison below. float: true preserves the initial vertical gaps.

Action Expected result
Auto arrange Places A → B → C in array order on the first row, keeping widths 3, 3, and 4.
Fill row widths A and B at the same y become 6 columns each; C’s separate row fills all 12 columns.
Give remaining width to A Keeps B at width 3 and expands A to 9. C is retained.
6 columns → rearrange → 12 columns Restores the last layout used at 12 columns.
Return to 6 columns Restores the layout retained for 6 columns.
Reset Restores the initial 12-column A/B/C layout.

autoArrangeWidgets packs rows in widget array order. fitWidgetsToColumns distributes free width among widgets at the same y. fitWidgetToColumns(id) gives that row’s remaining width to a specific widget. These are not the same operation as the engine’s compact().

setColumns retains per-column geometry and restores it when revisiting a column count. This example explicitly changes columns; it does not demonstrate automatic responsive breakpoints based on container width.

Wire widgets, columns, and refreshKey to the hook result, and onLayoutCommit to commands.applyLayoutSnapshot. Dragging and resizing also appear in the JSON below. Do not overwrite initial state through prop changes; request a reset with commands.resetLayout().

The table assumes this example’s unconstrained widgets. Added min/max size constraints and engine settings can change the final geometry.

The displayed JSON contains only the current column geometry. To persist per-column caches too, store serializeState() and restore it with restoreLayout(). This example runs in browser memory and does not restore across page reloads.

20 state commands · Initial options · Engine compact · Persistence