View as Markdown

API reference: @salmonui/data-grid

DataGridcomponent

import { DataGrid } from '@salmonui/data-grid';
function DataGrid<Row>(props: DataGridProps<Row>): import("react").JSX.Element;

Virtualized data grid (React 19). One scroll container, one role="grid" tree, sticky header, frozen columns outside horizontal virtualization. DataGrid state lives in the @salmonui/data-grid/engine engine; scroll and drag transients live in a renderer-local layout store and the DOM.

Render features: the features the initial props need are computed once. When none is needed, or the features prop provides every needed one, the view renders directly with them. Otherwise a gate reads them from the registry (#data-grid-features); the grid has no Suspense boundary of its own. The server registry answers synchronously, so the server markup is the plain grid in every SSR mode. While hydrating, a gate whose chunk has not arrived throws the pending load to the nearest ancestor boundary (or the root), which keeps the server HTML and hydrates when the chunk arrives. On a client-only first use the placeholder shows for one chunk round trip.

Props: DataGridProps

DataGrid props (163)
NameSignatureDescription
dataoptionaldata?: readonly Row[] | DataSource<Row>;

Rows (reactive: a new array replaces the rows) or a DataSource (read once on mount).

columnsoptionalcolumns?: readonly DataGridColumn<Row>[];

Column definitions; <DataGridColumn> children are the JSX form (children win over columns).

childrenoptionalchildren?: ReactNode;

<DataGridColumn> and <DataGridAggregateRow> elements.

getRowIdoptionalgetRowId?: (row: Row) => RowId | number;

Row identity. Default: the primaryKey column(s), else the id field (with a development warning).

modulesoptionalmodules?: readonly DataGridModule<Row>[];

Extra core modules (initial only).

featuresoptionalfeatures?: readonly DataGridFeature[];

Salmon. Render features to use synchronously, from @salmonui/data-grid/features. Optional: a grid loads the features its props need on demand; features passed here skip that load (no placeholder on a client-only render). Read at creation.

localeoptionallocale?: string;
timeZoneoptionaltimeZone?: string;

IANA time zone for date formatting. Set it for SSR: server and client must format identically.

currencyoptionalcurrency?: string;
diroptionaldir?: 'ltr' | 'rtl' | 'auto';

Text direction. 'auto' follows the locale script (ar, he, fa, ... are right-to-left). Default: the inherited dir. Reactive.

heightoptionalheight?: number | string;

Viewport height: px, any CSS length ('100%' needs a fixed-height parent), or 'auto' (no row virtualization). Default 400.

widthoptionalwidth?: number | string;
rowHeightoptionalrowHeight?: number;

Fixed row height in px. Default 36.

getRowHeightoptionalgetRowHeight?: (row: Row) => number;

Per-row fixed height.

estimatedRowHeightoptionalestimatedRowHeight?: number;

Enables measured row heights with this estimate (variable content, templates, wrapping).

headerHeightoptionalheaderHeight?: number;

Header row height in px (per stacked level). Default 40.

defaultColumnWidthoptionaldefaultColumnWidth?: number;

Width of columns without width. Default 160.

virtualizationoptionalvirtualization?: boolean | DataGridVirtualization;

Row and column virtualization; true (default) for the defaults, false renders every row and column.

infiniteScrolloptionalinfiniteScroll?: boolean | DataGridInfiniteScroll<Row>;

Infinite scrolling for remote sources: rows load in blocks as the viewport approaches them.

renderLoadingRowoptionalrenderLoadingRow?: (ctx: DataGridLoadingRowContext) => ReactNode;

Placeholder row while its block loads, or after the load failed. Default: the loading text, or the error and a Retry button.

initialRowsoptionalinitialRows?: number;

Rows in the deterministic server/initial range. Default 20.

initialColumnsoptionalinitialColumns?: number;

Center columns in the deterministic server/initial range. Default 20.

textWrapoptionaltextWrap?: DataGridTextWrap;
gridLinesoptionalgridLines?: DataGridLines;
overflowoptionaloverflow?: DataGridOverflow;

Default text overflow of every column. Default ellipsis.

highlightOnHoveroptionalhighlightOnHover?: boolean;

Row hover highlight. Default true.

stripedoptionalstriped?: boolean;

Alternate row shading. Default true.

resizableoptionalresizable?: boolean;

Pointer and keyboard column resize. Default false; column resizable refines it.

resizeModeoptionalresizeMode?: 'normal' | 'auto';

Column fit. 'normal' (default): widths are kept, leaving empty space or scrolling. 'auto': when the columns are narrower than the grid they stretch proportionally to fill it, and a pointer resize re-fits the other columns.

reorderableoptionalreorderable?: boolean;

Pointer and keyboard column reorder. Default false; column reorderable refines it.

onBeforeColumnVisibilityChangeoptionalonBeforeColumnVisibilityChange?: (event: DataGridColumnVisibilityChangeEvent) => void;
onColumnVisibilityChangeoptionalonColumnVisibilityChange?: (event: DataGridColumnVisibilityChangeEvent) => void;
onBeforeColumnReorderoptionalonBeforeColumnReorder?: (event: DataGridColumnReorderEvent) => void;
onColumnReorderoptionalonColumnReorder?: (event: DataGridColumnReorderEvent) => void;
groupingoptionalgrouping?: boolean | DataGridGrouping<Row>;

true or settings: grouping UI and behavior.

onBeforeGroupChangeoptionalonBeforeGroupChange?: (event: DataGridGroupChangeEvent) => void;
onGroupChangeoptionalonGroupChange?: (event: DataGridGroupChangeEvent) => void;
onBeforeGroupToggleoptionalonBeforeGroupToggle?: (event: DataGridGroupToggleEvent<Row>) => void;
onGroupToggleoptionalonGroupToggle?: (event: DataGridGroupToggleEvent<Row>) => void;
aggregatesoptionalaggregates?: readonly DataGridAggregateRow<Row>[];

Aggregate rows (or <DataGridAggregateRow> children).

aggregateScopeoptionalaggregateScope?: 'page' | 'all';

With paging: page (default) aggregates the current page, all every matching row.

renderRowoptionalrenderRow?: (ctx: DataGridRowContext<Row>) => ReactNode;
renderEmptyoptionalrenderEmpty?: (ctx: DataGridEmptyContext) => ReactNode;
renderErroroptionalrenderError?: (ctx: DataGridDataErrorContext) => ReactNode;

Body content while the data source failed to load. Default: the error message and a Retry button.

onViewChangeoptionalonViewChange?: (event: DataGridViewChangeEvent) => void;

Once per committed change of the displayed rows; never on scroll, focus, selection, or expansion.

getRowPropsoptionalgetRowProps?: (row: Row, rowIndex: number, ctx: { readonly tree?: DataGridTreeContext; }) => DataGridElementProps | undefined;

Called for rendered rows only; ctx.tree in tree mode.

rowClassNameoptionalrowClassName?: (row: Row, rowIndex: number) => string | undefined;
getCellPropsoptionalgetCellProps?: (ctx: DataGridCellContext<Row>) => DataGridElementProps | undefined;

Called for rendered cells only.

classNameoptionalclassName?: string;
styleoptionalstyle?: CSSProperties;
classNamesoptionalclassNames?: Partial<Record<DataGridPart, string>>;
stylesoptionalstyles?: Partial<Record<DataGridPart, CSSProperties>>;
iconsoptionalicons?: DataGridIcons | undefined;

Icon overrides by name: a node replaces the built-in SVG icon, null hides it. Merges over an enclosing DataGridIconsProvider. A component prop, not a theme input.

refoptionalref?: Ref<DataGridApi<Row>>;

Receives the grid instance; the root element is api.element.

idoptionalid?: string;
aria-labeloptional'aria-label'?: string;
aria-labelledbyoptional'aria-labelledby'?: string;
aria-describedbyoptional'aria-describedby'?: string;
onWarningoptionalonWarning?: (warning: DataGridWarning) => void;
onReadyoptionalonReady?: (api: DataGridApi<Row>) => void;

Fires once after the first commit with the instance.

selectionoptionalselection?: boolean | DataGridSelection;

Selection. On by default: single row selection. false turns it off.

onBeforeSelectionChangeoptionalonBeforeSelectionChange?: (event: DataGridSelectionChangeEvent<Row>) => void;

Cancel with event.preventDefault().

onSelectionChangeoptionalonSelectionChange?: (event: DataGridSelectionChangeEvent<Row>) => void;
keyBindingsoptionalkeyBindings?: Readonly<Record<string, readonly string[]>>;

Replaces the combos of keyboard commands ({ 'selection.selectAll': ['Mod+Shift+L'] }). Reactive: a changed value (compared by value) rebuilds the keymap.

onKeyDownoptionalonKeyDown?: (ctx: DataGridKeyDownContext) => void;

Called for every key pressed in the grid before the built-in binding runs.

localeTextoptionallocaleText?: DataGridLocaleText;

Text overrides over the English catalog (DATA_GRID_DEFAULT_LOCALE_TEXT): every visible and assistive string of the grid. Plain JSON with {param} templates and plural forms. Reactive.

persistStateoptionalpersistState?: boolean | DataGridPersistState;

Saves the user's grid state (column order, widths, visibility, pinning, sorting, filters, grouping, page, search, selection, scroll) and restores it on mount. true uses localStorage under salmon-data-grid:<id> (set id); an object sets the key, storage, excluded parts, and an application version. Read on mount.

pinnedColumnsoptionalinheritedpinnedColumns?: DataGridPinnedColumns;

The first / last N visible columns are pinned. Reactive.

stickyRowsoptionalinheritedstickyRows?: number;

The first N rows of the visible row model stick below the header.

stickyBottomRowsoptionalinheritedstickyBottomRows?: number;

The last N rows of the visible row model stick above the footer.

onBeforeColumnPinChangeoptionalinheritedonBeforeColumnPinChange?: ((event: DataGridColumnPinChangeEvent) => void);
onColumnPinChangeoptionalinheritedonColumnPinChange?: ((event: DataGridColumnPinChangeEvent) => void);
mergeCellsoptionalinheritedmergeCells?: DataGridMergeCells;

DataGrid-wide merging of equal adjacent values (row merging also works under row virtualization).

columnMenuoptionalinheritedcolumnMenu?: boolean | readonly (DataGridMenuItem | DataGridColumnMenuItemId)[];

Column menu; an array lists the items in order (built-in ids or custom items). column.menu: false opts a column out.

onBeforeColumnMenuOpenoptionalinheritedonBeforeColumnMenuOpen?: ((event: DataGridColumnMenuOpenEvent<Row>) => void);
onBeforeColumnMenuCloseoptionalinheritedonBeforeColumnMenuClose?: ((event: DataGridColumnMenuCloseEvent<Row>) => void);
onColumnMenuItemClickoptionalinheritedonColumnMenuItemClick?: ((event: DataGridColumnMenuItemClickEvent<Row>) => void);
renderColumnMenuoptionalinheritedrenderColumnMenu?: ((ctx: DataGridColumnMenuContext<Row>) => ReactNode);
columnChooseroptionalinheritedcolumnChooser?: boolean | DataGridColumnChooser<Row>;
onBeforeColumnChooserOpenoptionalinheritedonBeforeColumnChooserOpen?: ((event: DataGridColumnChooserOpenEvent<Row>) => void);
toolbaroptionalinheritedtoolbar?: readonly (DataGridToolbarItem | DataGridToolbarItemId)[];
onToolbarItemClickoptionalinheritedonToolbarItemClick?: ((event: DataGridToolbarItemClickEvent) => void);
renderToolbaroptionalinheritedrenderToolbar?: ((ctx: DataGridToolbarContext<Row>) => ReactNode);
contextMenuoptionalinheritedcontextMenu?: boolean | readonly (DataGridMenuItem | DataGridContextMenuItemId)[];

Context menu; an array lists the items in order. Items that do not apply to the target are dropped.

onBeforeContextMenuOpenoptionalinheritedonBeforeContextMenuOpen?: ((event: DataGridContextMenuOpenEvent) => void);
onBeforeContextMenuCloseoptionalinheritedonBeforeContextMenuClose?: ((event: DataGridContextMenuCloseEvent) => void);
onContextMenuItemClickoptionalinheritedonContextMenuItemClick?: ((event: DataGridContextMenuItemClickEvent<Row>) => void);
renderContextMenuoptionalinheritedrenderContextMenu?: ((ctx: DataGridContextMenuContext) => ReactNode);
onColumnResizeStartoptionalinheritedonColumnResizeStart?: ((event: DataGridColumnResizeEvent) => void);
onColumnResizeoptionalinheritedonColumnResize?: ((event: DataGridColumnResizeEvent) => void);
onColumnResizeEndoptionalinheritedonColumnResizeEnd?: ((event: DataGridColumnResizeEvent) => void);
onColumnDragStartoptionalinheritedonColumnDragStart?: ((event: DataGridColumnDragEvent) => void);
onColumnDragoptionalinheritedonColumnDrag?: ((event: DataGridColumnDragEvent) => void);
onColumnDropoptionalinheritedonColumnDrop?: ((event: DataGridColumnDragEvent) => void);
adaptiveoptionalinheritedadaptive?: boolean | DataGridAdaptive;

Adaptive UI (enableAdaptiveUI, adaptiveUIMode, rowRenderingMode): full-screen sheets for menus and dialogs, 44 px touch targets, touch long-press, and optional vertical (card) rows. true is { target: 'both' }.

onBeforeAdaptiveDialogOpenoptionalinheritedonBeforeAdaptiveDialogOpen?: ((event: DataGridAdaptiveDialogOpenEvent) => void);
onBeforeCopyoptionalinheritedonBeforeCopy?: ((event: DataGridBeforeCopyEvent) => void);
onBeforePasteoptionalinheritedonBeforePaste?: ((event: DataGridBeforePasteEvent) => void);
onBeforeFilloptionalinheritedonBeforeFill?: ((event: DataGridBeforeFillEvent) => void);
editingoptionalinheritedediting?: boolean | DataGridEditing<Row>;

Editing. true for the defaults (row mode). The module is registered when the initial value is set.

onBeforeEditStartoptionalinheritedonBeforeEditStart?: ((event: DataGridEditStartEvent<Row>) => void);
onEditStartoptionalinheritedonEditStart?: ((event: DataGridEditStartEvent<Row>) => void);
onBeforeCellValueChangeoptionalinheritedonBeforeCellValueChange?: ((event: DataGridCellValueChangeEvent) => void);
onCellValueChangeoptionalinheritedonCellValueChange?: ((event: DataGridCellValueChangeEvent) => void);
onBeforeSaveoptionalinheritedonBeforeSave?: ((event: DataGridSaveEvent<Row>) => void);
onSaveoptionalinheritedonSave?: ((event: DataGridSaveEvent<Row>) => void);
onBeforeAddoptionalinheritedonBeforeAdd?: ((event: DataGridAddEvent<Row>) => void);
onAddoptionalinheritedonAdd?: ((event: DataGridAddEvent<Row>) => void);
onBeforeDeleteoptionalinheritedonBeforeDelete?: ((event: DataGridDeleteEvent<Row>) => void);
onDeleteoptionalinheritedonDelete?: ((event: DataGridDeleteEvent<Row>) => void);
onBeforeEditCanceloptionalinheritedonBeforeEditCancel?: ((event: DataGridEditCancelEvent) => void);
onEditCanceloptionalinheritedonEditCancel?: ((event: DataGridEditCancelEvent) => void);
onCommandClickoptionalinheritedonCommandClick?: ((event: DataGridCommandClickEvent<Row>) => void);
sortingoptionalinheritedsorting?: boolean | DataGridSorting;

true or options: header sorting.

filteringoptionalinheritedfiltering?: boolean | DataGridFiltering;

true or options: filtering and its UI.

searchoptionalinheritedsearch?: boolean | DataGridSearch;

true or options: searching.

pagingoptionalinheritedpaging?: boolean | DataGridPaging;

true or options: paging and the pager.

renderPageroptionalinheritedrenderPager?: ((ctx: DataGridPagerContext) => ReactNode);

Replaces the pager.

onBeforeSortChangeoptionalinheritedonBeforeSortChange?: ((event: DataGridSortChangeEvent) => void);
onSortChangeoptionalinheritedonSortChange?: ((event: DataGridSortChangeEvent) => void);
onBeforeFilterChangeoptionalinheritedonBeforeFilterChange?: ((event: DataGridFilterChangeEvent) => void);
onFilterChangeoptionalinheritedonFilterChange?: ((event: DataGridFilterChangeEvent) => void);
onBeforeFilterMenuOpenoptionalinheritedonBeforeFilterMenuOpen?: ((event: DataGridFilterMenuOpenEvent) => void);
onFilterMenuOpenoptionalinheritedonFilterMenuOpen?: ((event: DataGridFilterMenuOpenEvent) => void);
onBeforeSearchChangeoptionalinheritedonBeforeSearchChange?: ((event: DataGridSearchChangeEvent) => void);
onSearchChangeoptionalinheritedonSearchChange?: ((event: DataGridSearchChangeEvent) => void);
onBeforePageChangeoptionalinheritedonBeforePageChange?: ((event: DataGridPageChangeEvent) => void);
onPageChangeoptionalinheritedonPageChange?: ((event: DataGridPageChangeEvent) => void);
onErroroptionalinheritedonError?: ((event: DataGridErrorEvent) => void);

An action was rejected (unknown column, page out of range, ...).

renderDetailoptionalinheritedrenderDetail?: ((ctx: DataGridDetailContext<Row>) => ReactNode);

Detail row content below each expanded row.

detailHeightoptionalinheriteddetailHeight?: number;

Estimated detail row height in px before measurement. Default 150.

hasDetailoptionalinheritedhasDetail?: ((row: Row) => boolean);

Rows without a detail (no toggle). Called for rendered rows only.

loadDetailoptionalinheritedloadDetail?: ((ctx: DataGridDetailLoadContext<Row>) => unknown);

Async detail content, started on expand; renderDetail receives status, data, error.

defaultExpandedDetailsoptionalinheriteddefaultExpandedDetails?: boolean | readonly string[];

Initially expanded details: true for every row, or row ids (initial only).

childGridoptionalinheritedchildGrid?: DataGridChildGrid<unknown, Row>;

Child grid inside each expanded row (hierarchy grid). An inline object sees child rows as unknown; defineChildGrid<Child, Parent>(config) types the child rows.

onBeforeDetailToggleoptionalinheritedonBeforeDetailToggle?: ((event: DataGridDetailToggleEvent<Row>) => void);
onDetailToggleoptionalinheritedonDetailToggle?: ((event: DataGridDetailToggleEvent<Row>) => void);
rowDragoptionalinheritedrowDrag?: boolean | DataGridRowDrag;

Row drag and drop with a drag handle column; true reorders within the grid.

onRowDragStartoptionalinheritedonRowDragStart?: ((event: DataGridRowDragEvent<Row>) => void);

Cancel with event.preventDefault().

onRowDragoptionalinheritedonRowDrag?: ((event: DataGridRowDragEvent<Row>) => void);

Once per animation frame while dragging.

onBeforeRowDropoptionalinheritedonBeforeRowDrop?: ((event: DataGridRowDragEvent<Row>) => void);

Cancel with event.preventDefault().

onRowDropoptionalinheritedonRowDrop?: ((event: DataGridRowDragEvent<Row>) => void);
renderRowDragPreviewoptionalinheritedrenderRowDragPreview?: ((ctx: DataGridRowDragPreviewContext<Row>) => ReactNode);

Drag preview content (default: the first cell text and the row count).

exportWritersoptionalinheritedexportWriters?: DataGridExportWriters;

Excel and PDF writer loaders; without one the matching toolbar and menu items are disabled.

onBeforeExportoptionalinheritedonBeforeExport?: ((event: DataGridBeforeExportEvent<Row>) => void);
onExportoptionalinheritedonExport?: ((event: DataGridExportEvent<Row>) => void);
printingoptionalinheritedprinting?: DataGridPrinting<Row>;

Print scope and hierarchy mode (print() options override them).

onBeforePrintoptionalinheritedonBeforePrint?: ((event: DataGridBeforePrintEvent) => void);
onAfterPrintoptionalinheritedonAfterPrint?: ((event: DataGridAfterPrintEvent) => void);
loadingIndicatoroptionalinheritedloadingIndicator?: "skeleton" | "spinner";

Built-in loading indicator. Default spinner.

renderLoadingoptionalinheritedrenderLoading?: ((ctx: DataGridLoadingContext) => ReactNode);

Replaces the content of the loading indicator (presentational: the grid announces loading itself).

onRowClickoptionalinheritedonRowClick?: ((event: DataGridRowClickEvent<Row>) => void);

A data row was clicked. preventDefault() skips the built-in selection and focus.

onRowDoubleClickoptionalinheritedonRowDoubleClick?: ((event: DataGridRowClickEvent<Row>) => void);

A data row was double-clicked. preventDefault() skips the built-in edit start.

onCellClickoptionalinheritedonCellClick?: ((event: DataGridCellClickEvent<Row>) => void);

A cell of a data row was clicked; fires before onRowClick.

onCellDoubleClickoptionalinheritedonCellDoubleClick?: ((event: DataGridCellClickEvent<Row>) => void);

A cell of a data row was double-clicked; fires before onRowDoubleClick.

recordCommandsoptionalinheritedrecordCommands?: boolean;

Keeps a serializable log of applied commands (api.engine.getCommandLog()). Initial only. Default false.

instrumentoptionalinheritedinstrument?: boolean;

Exposes store counters (api.engine.getInstrumentation()). Initial only. Default false.

treeoptionalinheritedtree?: boolean | DataGridTree<Row>;

Tree mode: rows with children, indented in the tree column. Read at creation (its options are reactive).

onBeforeTreeToggleoptionalinheritedonBeforeTreeToggle?: ((event: DataGridTreeToggleEvent<Row>) => void);
onTreeToggleoptionalinheritedonTreeToggle?: ((event: DataGridTreeToggleEvent<Row>) => void);
isRowPinnedoptionalinheritedisRowPinned?: ((row: Row) => boolean);

Rows pinned to the top zone. Pinned rows stay visible above the scrolling rows on every page, are left out of pageSize, and follow sorting, filtering, search and edits. Pure; read once when the grid is created. Turns row pinning on.

defaultPinnedRowsoptionalinheriteddefaultPinnedRows?: readonly string[];

Initially pinned row ids (initial only). Turns row pinning on; pass [] to only use pinRows.

onBeforeFilterBuilderOpenoptionalinheritedonBeforeFilterBuilderOpen?: ((event: DataGridFilterBuilderOpenEvent) => void);