-
Notifications
You must be signed in to change notification settings - Fork 0
Column Resizing
📝 Generated from
docs/components/column-resize.md. Edit it there; changes made in the wiki are overwritten.
OpenGridX supports dynamic column resizing, allowing users to adjust the width of any column on the fly for better visibility of data. This is facilitated by the ColumnResizeHandle, an internal component (not exported) that <Header /> renders invisibly on the edge of each resizable column header.
- Where the handle is: on the right edge of each resizable column header. Right-pinned columns are anchored to the right edge of the grid and grow leftwards, so their handle is on their left edge, and the edge you grab follows the pointer. The handle is an 8px strip just inside the column, against that edge, and all of it can be grabbed (v3.0.1+; before, the neighbouring header cell clipped half of it).
- Mouse, touch and pen: the handle uses pointer events with pointer capture, so a resize keeps following the pointer outside the header and works on tablets and phones.
-
Keyboard: with a column header focused, Alt+ArrowRight / Alt+ArrowLeft widen / narrow the column by 10px (hold Shift for 50px). The handle is a
role="separator"that reports the width inaria-valuenow(andaria-valuemin/aria-valuemax). -
Constraints:
minWidthandmaxWidthfrom yourGridColDefapply. WithoutminWidtha column can be narrowed to 50px; a column that is already narrower (a 30px icon column) is never snapped up to 50px. WithoutmaxWidththere is no upper limit. - Clicks are not resizes: pressing and releasing the handle without moving it changes nothing (a flex column stays flex), and ending a resize with the pointer over the header never sorts the column.
-
Double-click to auto-size (v3.1.0+): double-clicking the handle fits the column to its content — the header (title, sort icon, menu button) and the cells rendered right now, i.e. the rows and pinned rows in the current virtualization window, not the whole data set. The width is clamped to
minWidth(default 50px) andmaxWidth; a flex column gets a fixed width, like after a manual drag. The double-click never sorts. With the handle focused, Enter does the same. Columns withresizable: falsehave no handle and are never auto-sized. -
Programmatic auto-size:
apiRef.current.autosizeColumn(field)andapiRef.current.autosizeColumns(fields?)(every column whenfieldsis omitted) use the same measurement. The new width lands incolumnWidthsstate like a drag, soonStateChangereports it; there is no dedicated resize callback.
By default, all columns are resizable. You can disable it for a specific field.
const columns: GridColDef[] = [
{ field: 'id', headerName: 'ID', resizable: false }, // Fixed width
{ field: 'name', headerName: 'Name', minWidth: 100 } // User can resize
];There is no single grid-wide prop to disable all column resizing. Set resizable: false on each column definition individually:
const columns: GridColDef[] = [
{ field: 'id', headerName: 'ID', resizable: false },
{ field: 'status', headerName: 'Status', resizable: false },
];const apiRef = useGridApiRef();
<DataGrid apiRef={apiRef} rows={rows} columns={columns} />
<button onClick={() => apiRef.current.autosizeColumns()}>Fit all columns</button>Measurement reads the DOM (each cell's .ogx__cell-content laid out at max-content, plus the cell's padding and borders), so only rendered rows count: scroll first, or turn off virtualization for a small grid, if off-screen rows are wider. Cells that span several columns (colSpan) are skipped.
-
Handle Deployment: every resizable header cell renders a
ColumnResizeHandle. -
Pointer processing: on
pointerdownthe handle captures the pointer and remembers the column's current width. Eachpointermove(throttled to one update per frame) sets the width to that start width plus the horizontal distance moved (minus it for a right-pinned column). -
Boundaries Enforcement: the width is clamped to the column's
minWidth/maxWidth(see above). -
Finalization: on
pointerupthe final width is stored in the grid'scolumnWidthsstate (part of theonStateChangesnapshot and ofinitialState.columns.columnWidths). A cancelled pointer (the browser took the gesture over) keeps the last width shown.
The resize handle is not replaceable via the slots API. Style it through CSS:
.ogx-column-resize-handle__line {
width: 4px;
background: #6366f1;
}
/* The handle of a right-pinned column, on its left edge */
.ogx-column-resize-handle--start { }
/* While a resize is in progress */
.ogx-column-resize-handle--dragging { }-
Define Min Widths: set a
minWidththat fits your column's content. -
Persistence: Use
onStateChangeto capture the currentcolumnWidthsfrom the state snapshot and save the user's preferred layout for their next visit. - Content Fit: Remember that large data values might hide behind narrow columns; use tooltips for overflow coverage.
OpenGridX 3.2.2 · MIT · This wiki is generated from docs/ on every push to main. To fix a page, open a PR against the source file.
Start here
Components
- DataGrid
- Header
- Row
- Cell
- Toolbar
- Pagination
- Filter Panel
- Tooltip
- Column Visibility
- Column Grouping
- Column Resizing
- Empty State
- Error Overlay
- Aggregation Footer
Features
- Virtualization
- Filtering & Search
- Sorting & Pagination
- Custom Pagination
- Editing & Reordering
- Row Selection
- Clipboard
- Pinning
- State Persistence
- Aggregation & Pivot
- Tree Data & Grouping
- Cell Spanning
- Master-Detail
- Keyboard & Accessibility
- List View
- Infinite Scroll
- Data Source
- Loading States
- Toolbar Customization
- Export (CSV, Excel, JSON, Print)
- PDF Export
Customization
Upgrading
Contributing
- Contributing
- Testing
- Roadmap
- DataGrid orchestration
- GridRowMeta
- useGridControlledState
- useGridRowPipeline
- useGridColumns
- useGridVirtualization
- useGridVisibleRows
- useGridScrollSync
- useGridStateSnapshot