Skip to content

Grid

High-performance flat data grid component.

Import

ts
import { Grid } from '@itsmemyk/react-tree-grid/grid'

Props

Data

PropTypeDefaultDescription
columnsGridColumn[]Column definitions (required)
dataGridRow[]Row data array (required unless store is set)
storeDataStoreData store for large/server-driven datasets
spansGridSpan[]Cell span definitions

Layout

PropTypeDefaultDescription
styleCSSPropertiesSet width and height to enable virtual scroll
classNamestringExtra CSS class on root element
rowHeightnumber34Default row height in px
headerRowHeightnumberHeader row height in px
footerRowHeightnumberFooter row height in px
autoWidthbooleanfalseDistribute remaining width across flexible columns
autoHeightbooleanfalseWrap rows to tallest cell height
headerAutoHeightbooleanfalseWrap header to tallest cell
adjustboolean | 'data' | 'header' | 'footer'Auto-fit column widths

Behaviour

PropTypeDefaultDescription
sortablebooleanfalseEnable sorting on all columns
editablebooleanfalseEnable inline cell editing
tooltipbooleanfalseShow cell value tooltip on overflow
keyNavigationbooleanfalseArrow key navigation between cells
selectionboolean | 'row' | 'cell' | 'complex'falseSelection mode
multiselectionbooleanfalseAllow multi-row/cell selection
leftSplitnumberFreeze N columns from the left
rightSplitnumberFreeze N columns from the right
topSplitnumberFreeze N header rows from the top
dragItem'row' | 'column'Enable drag-and-drop for rows or columns
dragMode'source' | 'target' | 'both'Drag role of this grid
formulasbooleanfalseEnable formula engine in cells

Events

Sort

PropSignatureDescription
onBeforeSort(states: SortState[]) => boolean | voidReturn false to cancel sort
onAfterSort(states: SortState[]) => voidFires after sort applied

Selection

PropSignatureDescription
onBeforeSelect(rowId, colId) => boolean | voidReturn false to cancel
onAfterSelect(rowId, colId) => voidFires after selection
onBeforeUnSelect(rowId, colId) => boolean | void
onAfterUnSelect(rowId, colId) => void
onCellClick(rowId, colId, event) => voidCell single click
onCellDblClick(rowId, colId, event) => voidCell double click

Editing

PropSignatureDescription
onBeforeEditStart(rowId, colId) => boolean | voidReturn false to prevent editing
onAfterEditStart(rowId, colId) => void
onBeforeEditEnd(rowId, colId, newValue, oldValue) => boolean | voidReturn false to reject value
onAfterEditEnd(rowId, colId, newValue) => voidFires after value saved

Column resize

PropSignatureDescription
onBeforeResizeStart(colId) => boolean | void
onResize(colId, width) => voidFires during drag
onAfterResizeEnd(colId, width) => voidFires after drag ends

Row drag

PropSignatureDescription
onBeforeRowDrag(data, event) => boolean | void
onDragRowStart(data, event) => void
canRowDrop(data, event) => boolean | voidReturn false to reject drop target
onBeforeRowDrop(data, event) => boolean | void
onAfterRowDrop(data, event) => void
onAfterRowDrag(data, event) => void

Column drag

PropSignatureDescription
onBeforeColumnDrag(data, event) => boolean | void
onDragColumnStart(data, event) => void
canColumnDrop(data, event) => boolean | void
onBeforeColumnDrop(data, event) => boolean | void
onAfterColumnDrop(data, event) => void

Scroll

PropSignatureDescription
onScroll({ x, y }) => voidFires on scroll

GridApi (ref)

Pass a ref to access the imperative API:

tsx
import { useRef } from 'react'
import type { GridApi } from '@itsmemyk/react-tree-grid/grid'

const ref = useRef<GridApi>(null)

<Grid ref={ref} columns={columns} data={data} />
MethodSignatureDescription
showColumn(colId: string) => voidMake a hidden column visible
hideColumn(colId: string) => voidHide a column
getColumn(colId: string) => GridColumn | undefinedGet column definition
setColumns(columns: GridColumn[]) => voidReplace all column definitions
addRowCss(rowId, css) => voidAdd a CSS class to a row
removeRowCss(rowId, css) => voidRemove a CSS class from a row
addCellCss(rowId, colId, css) => voidAdd a CSS class to a cell
removeCellCss(rowId, colId, css) => voidRemove a CSS class from a cell

Released under the MIT License.