Pro (paid add-on)
DataGridPro
ProDataGridPro is the free DataGrid with the tools data-heavy apps need: columns people can resize, pin, move and hide, filters, grouping with subtotals, tree data, editing in the cell, and copy and paste with spreadsheets.
Part of Pro
This page documents part of @vjdesigns-pro/ui, the paid add-on package. Using it needs a Pro license and @vjdesigns/vjdesigns-ui 3.8.0 or later. Like the free package, it works in both modes, every brand, all 32 languages and right to left. Install it as described in Account forms.
DataGrid or DataGridPro
DataGrid is free. It sorts, searches, selects and pages, works with server-side data, has a full keyboard grid, and stays fast at 100,000 rows. DataGridPro takes every DataGrid prop and adds:
- Column tools: resizing, pinning, moving, hiding and a column menu, with layouts you can save.
- Filters per column, shown as chips above the grid.
- Grouping with subtotals, tree data and master-detail rows.
- Editing in the cell, with validation.
- Copy and paste of cell blocks, to and from spreadsheets.
- Loading while scrolling for server-side data.
Example
Columns add width, minWidth, maxWidth (in px), resizable and pinned, plus the per-column switches menu, hideable, reorderable and pinnable.
import { DataGridPro } from "@vjdesigns-pro/ui";
<DataGridPro
aria-label="Season games"
rows={games}
columns={[
{ key: "opponent", header: "Opponent", pinned: "start", width: 180, sortable: true, rowHeader: true },
{ key: "points", header: "PTS", headerLabel: "Points", numeric: true, width: 90, sortable: true },
{ key: "notes", header: "Notes", pinned: "end", width: 220 },
]}
columnWidths={savedWidths}
onColumnWidthsChange={saveWidths}
selectionMode="multiple"
pageSize={25}
/>;
Column tools
- Resizing: drag a header's edge; double-click it to restore the starting width. From the keyboard, focus a header, press F2, then Tab to the resize handle: Arrow Left and Arrow Right change the width by 10 px (50 with Shift), Home and End jump to the limits, Enter restores it and Escape goes back to the grid.
- Pinning:
pinned: "start"or"end"keeps a column at that edge while the grid scrolls sideways. It follows the text direction, sostartis the right edge in right-to-left layouts. - Column menu: every header gets a menu button to sort, pin, move and hide the column. Columns shows hidden ones again, and Reset columns restores the default layout. From the keyboard, press Alt+Arrow Down on a header. Moves, hides and pins are announced.
- Moving columns: drag a header to a new place, or use Move left and Move right in the menu. Columns move within their group (start-pinned, unpinned, end-pinned).
- Saved layouts: widths, order, hidden columns and pinning can each be controlled (
columnWidths,columnOrder,hiddenColumns,columnPinning), with adefault…prop and anon…Changecallback, ready foruseLocalStorageor your backend. At least one column always stays visible.
Filters
Every column gets a filter button in its header. Text, number and date columns filter by a condition ("Contains", "Greater than", "Between", "Is empty" and so on); filter: "values" gives a searchable checklist of the column's values with counts. Active filters show as chips above the grid, with "Clear all filters", and the new row count is announced. Filters are plain data; with manual (server-side data) the grid reports them, and applyFilters and matchesFilter let your server apply the same rules.
<DataGridPro
columns={[
{ key: "opponent", header: "Opponent" }, // text
{ key: "venue", header: "Venue", filter: "values" }, // choose from values
{ key: "date", header: "Date", filter: "date" },
{ key: "points", header: "PTS", numeric: true }, // number
{ key: "notes", header: "Notes", filter: false }, // no filter
]}
filters={filters}
onFiltersChange={setFilters}
…
/>
Grouping, tree data and master-detail
- Grouping:
groupBy={["venue"]}(or "Group by" in a column's menu) adds a header row per value with its row count and the subtotals of columns that setaggregate("sum","avg","min","max","count"or a function). Groups nest and collapse. - Tree data:
getChildren={(row) => row.children}makesrowsthe top level; rows with children get a toggle. A search or filter keeps the rows above a match. - Master-detail:
renderDetail={(row) => <Details row={row} />}adds a toggle that opens a full-width panel under the row. Tab moves from the row into its details. - Grouped and tree grids are
treegrids: each row carries its level and expanded state, and the toggles are buttons witharia-expanded.
Editing
Mark columns editable and handle onCellEdit. Enter, F2, typing or a double-click starts editing; Enter saves, Tab saves and moves to the next editable cell, and Escape cancels. Editors are text, number, date, select or your own. required and validate errors, and errors returned from onCellEdit, keep the editor open, are tied to it with aria-invalid and aria-describedby, and are announced.
<DataGridPro
columns={[
{ key: "opponent", header: "Opponent", editable: true, required: true },
{
key: "venue",
header: "Venue",
editable: true,
editor: "select",
options: [{ value: "Home", label: "Home" }, { value: "Away", label: "Away" }],
},
{
key: "points",
header: "PTS",
numeric: true,
editable: true,
validate: (v) => (v < 0 ? "Can't be negative." : null),
},
]}
onCellEdit={async (row, key, value) => {
const error = await save(row.id, key, value);
if (error) return error; // keeps the cell editing, with this message
setRows((list) => list.map((r) => (r.id === row.id ? { ...r, [key]: value } : r)));
}}
…
/>
Copy and paste
cellSelection lets people select a block of cells (Shift with the arrow keys, a drag, or Shift+click). Copy puts it on the clipboard as tab-separated text that Excel, Numbers and Google Sheets paste as cells. Paste fills editable cells from the focused cell; each value is checked like an edit, values that don't fit are skipped, and the result is announced ("Pasted into 3 cells, 1 cell skipped").
Loading while scrolling
For server-side data, onLoadMore is called when the rows in view come within loadMoreThreshold (20) rows of the end, while hasMore is true and loadingMore is false. Append the new rows to rows; a "Loading more rows…" status shows and is announced meanwhile.
Props
DataGridPro
DataGrid with Pro column tools:
- resizable columns (drag the header edge, or press F2 on a header, Tab to its handle, and use the arrow keys);
- pinned columns that stay in view while the grid scrolls sideways;
- a header menu (its button, or Alt+ArrowDown on the header) to sort, pin, move, and hide a column, and show hidden ones again from "Columns";
- drag a header to move its column (the menu's "Move left/right" does the same from the keyboard).
Every other DataGrid feature and prop works the same: sorting, filtering, selection, pagination, server-side mode, and the grid keyboard model. Widths, order, hidden columns, and pinning can each be controlled, so a saved layout can be restored. Pinning follows the text direction (start is the right edge in RTL). With multiple selection, the checkbox column is pinned along with any start columns. Columns move within their pin group.
<DataGridPro
aria-label="Roster"
rows={players}
columns={[
{ key: "name", header: "Player", pinned: "start", width: 200, sortable: true },
{ key: "ppg", header: "PPG", numeric: true, width: 96 },
]}
onColumnWidthsChange={saveLayout}
onColumnOrderChange={saveOrder}
/>
| Prop | Type | Default |
|---|---|---|
columnsRequiredThe columns, with Pro sizing and pinning, in their default order. | readonly DataGridProColumn<T>[] | — |
resizableColumnsColumns get a resize handle (pointer and keyboard). Per column, | boolean | true |
columnWidthsColumn widths in px, by key (controlled). | DataGridColumnWidths | — |
defaultColumnWidthsInitial widths when uncontrolled. Columns not listed use their | DataGridColumnWidths | — |
onColumnWidthsChangeCalled with every width while a column is resized. Persist it to remember a layout. | (widths: DataGridColumnWidths) => void | — |
defaultColumnWidthWidth of columns with no | number | 160 |
columnMenuEach header gets a menu button (also opened with Alt+ArrowDown on the header) to sort, pin, move, and hide the column, with a "Columns" list to show hidden columns again. Per column, | boolean | true |
reorderableColumnsColumns can be moved by dragging their header, or from their menu. Per column, | boolean | true |
columnOrderColumn keys in display order (controlled). Unknown keys are ignored; columns not listed follow in definition order. | string[] | — |
defaultColumnOrderInitial order when uncontrolled. | string[] | — |
onColumnOrderChangeCalled with every column key, in the new order, after a column moves. | (order: string[]) => void | — |
hiddenColumnsKeys of hidden columns (controlled). At least one column always stays visible. | string[] | — |
defaultHiddenColumnsInitially hidden columns when uncontrolled. | string[] | — |
onHiddenColumnsChangeCalled with the hidden keys after a column is hidden or shown. | (hidden: string[]) => void | — |
columnPinningPin sides by key (controlled). Overrides each column's | DataGridColumnPinning | — |
defaultColumnPinningInitial pinning when uncontrolled. | DataGridColumnPinning | — |
onColumnPinningChangeCalled after a column is pinned or unpinned from its menu. | (pinning: DataGridColumnPinning) => void | — |
columnFiltersEach header gets a filter button (also "Filter" in its menu). Active filters show as chips above the grid. Per column, | boolean | true |
filtersColumn filters by key (controlled). With | DataGridFilters | — |
defaultFiltersInitial filters when uncontrolled. | DataGridFilters | — |
onFiltersChangeCalled with every active filter after one is applied, changed, or removed. | (filters: DataGridFilters) => void | — |
groupByColumn keys to group rows by, outermost first (controlled). Each group gets a header row with its value, row count, and column subtotals, and collapses. Grouped grids show every row (no pages); sorting applies inside each group. | string[] | — |
defaultGroupByInitial grouping when uncontrolled. | string[] | — |
onGroupByChangeCalled when the user groups or ungroups by a column. | (groupBy: string[]) => void | — |
getChildrenTree data: each row's child rows. | (row: T) => readonly T[] | undefined | — |
expandedRowsIds of expanded tree rows (controlled). | string[] | — |
defaultExpandedRowsInitially expanded tree rows when uncontrolled. | string[] | [] |
onExpandedRowsChangeCalled when a tree row is expanded or collapsed. | (expanded: string[]) => void | — |
renderDetailMaster-detail: content shown in a full-width row under a row, opened from a toggle in its first cell. Tab moves from the row into its details. A grid with details doesn't virtualize; pair it with | (row: T) => ReactNode | — |
expandedDetailsIds of rows with their details open (controlled). | string[] | — |
defaultExpandedDetailsInitially open details when uncontrolled. | string[] | [] |
onExpandedDetailsChangeCalled when a row's details open or close. | (expanded: string[]) => void | — |
onCellEditTurns on inline editing for | (row: T, key: string, value: unknown) => void | string | null | undefined | Promise<void | string | null | undefined> | — |
cellSelectionCell ranges: Shift with the arrow keys, a drag, or Shift+click selects a block of cells. Copy puts it on the clipboard as tab-separated text (what spreadsheets use); paste fills editable cells from the focused cell (or repeats one value across the range), with each value checked like an edit. | boolean | false |
onCellsPasteSaves a paste in one go: every valid change, in order. Without it, each change goes through | (changes: { row: T; key: string; value: unknown; }[]) => void | Promise<void> | — |
onLoadMoreLoading while scrolling (server-side data): called when the rows in view come within | () => void | — |
hasMoreMore rows can be loaded. | boolean | false |
loadingMoreRows are loading: shows (and announces) a status under the grid. | boolean | false |
loadMoreThresholdHow close to the end, in rows, | number | 20 |
DataGridProColumn
A DataGrid column with Pro sizing, pinning, and column management. Widths are in px.
| Prop | Type | Default |
|---|---|---|
widthStarting width in px. Falls back to the grid's | number | — |
minWidthNarrowest the user can make it, in px. | number | 64 |
maxWidthWidest the user can make it, in px. | number | 800 |
resizableLet the user resize this column. | boolean | the grid's `resizableColumns` |
pinnedKeep the column in view while scrolling sideways. Pinned columns move to that edge, in their order. The grid's | "start""end" | — |
menuShow this column's header menu. | boolean | the grid's `columnMenu` |
hideableLet the user hide this column (from its menu or the "Columns" list). | boolean | true |
reorderableLet the user move this column (drag its header, or "Move left/right" in its menu). | boolean | the grid's `reorderableColumns` |
pinnableLet the user pin and unpin this column from its menu. | boolean | true |
filterHow this column is filtered: | false"number""text""values""date" | "number" for numeric columns, otherwise "text" (when the grid has `columnFilters`) |
groupableLet the user group rows by this column (from its menu). | boolean | true |
aggregateThe subtotal this column shows in each group row: | DataGridAggregate<T> | — |
editableCells of this column can be edited (with the grid's | boolean | ((row: T) => boolean) | — |
editorHow the cell is edited: | DataGridEditorType | ((props: DataGridEditorProps<T>) => ReactNode) | "number" for numeric columns, otherwise "text" |
optionsChoices for a | readonly { value: string; label: string; }[] | — |
requiredAn edit can't leave this cell empty. | boolean | — |
validateChecks an edit before it's saved: return an error message to show, or nothing when it's valid. | (value: unknown, row: T) => string | null | undefined | — |
DataGridColumnFilter
One column's filter.
| Prop | Type | Default |
|---|---|---|
operatorThe condition (text, number, and date filters). | "contains""equals""notEquals""startsWith""greaterThan""lessThan""between""before""after""isEmpty""isNotEmpty" | — |
valueThe value to compare with. Dates are "YYYY-MM-DD". | string | number | — |
value2The upper bound, for | string | number | — |
valuesThe chosen values, for a | readonly string[] | — |
FilterableColumn
A column as filtering sees it: its key, how it's filtered, and how its value is read.
| Prop | Type | Default |
|---|---|---|
keyRequired | string | — |
typeRequired | "text""number""date""values" | — |
valueRequired | (row: T) => unknown | — |