Command palette

@yasinsensoy/web

Web · Components

DataGrid

Professional data table for large data: virtualization, multi-sort, filters, search, column resize/move/pin/hide, row and cell range selection, validated cell editing, copy/paste, undo, grouping and totals, detail rows, tree data, server mode, pagination, infinite scroll, CSV export.

24 exports

Live example

Preview

Orders
Drag a column header here to group
1,000 records

Code

import { DataGrid, Badge } from "@yasinsensoy/web";

const [rows, setRows] = useState(orders);

<DataGrid
  title="Orders"
  rows={rows}
  rowKey="id"
  selection="multiple"
  groupable
  storageKey="orders"
  height={520}
  onCellsChange={(changes) => setRows((old) => uygula(old, changes))}
  columns={[
    { key: "no", header: "Order", width: 120, pinned: "start" },
    { key: "customer", header: "Customer", flex: 1, editable: true, validate: (v) => (v ? null : "Zorunlu") },
    { key: "city", header: "City", type: "select", options: cities, editable: true },
    { key: "status", header: "Durum", type: "select", options: durumlar, render: ({ value }) => <Badge>{value}</Badge>, aggregate: "count" },
    { key: "date", header: "Tarih", format: "date" },
    { key: "total", header: "Tutar", format: "currency", aggregate: "sum", editable: true },
    { key: "discount", header: "Discount", format: "percent", aggregate: "avg" },
    { key: "paid", header: "Paid", type: "boolean", editable: true },
  ]}
/>

Events

  1. Events appear here when you interact with the preview.

Tree data (file explorer, folders load when opened)

3 records

Server mode (sorting, filter, search, paging on the server)

0 records
Per page

Infinite scrolling

60 records

Import

import { DataGrid } from "@yasinsensoy/web";

DataGrid

componentClient component

Professional data table for large data: virtualization, multi-sort, filters, search, column resize/move/pin/hide, row and cell range selection, validated cell editing, copy/paste, undo, grouping and totals, detail rows, tree data, server mode, pagination, infinite scroll, CSV export. It is a client component.

For simple, server-rendered tables Table is lighter.

  • Performance: Only visible rows and columns are rendered; hundreds of thousands of rows and hundreds of columns scroll smoothly. Typing in filters and search does not stall the UI (deferred computation).
  • Sorting: Click a header; Shift adds a second column (a priority number appears).
  • Filter: "Filter…" from the ⋮ menu in the header: conditions by type (contains, greater than, between, empty…) or an Excel-like value list.
  • Columns: Drag the edge (double-click: fit to content), drag the header to move, pin to start/end from the menu, hide/show from the "Columns" panel. The layout is stored with storageKey.
  • Keyboard: Arrows, Home/End, Ctrl+Home/End, PageUp/PageDown; range selection with Shift; Ctrl+A selects all; Enter/F2 or starting to type edits, Enter/Tab saves and moves on, Esc cancels; Delete clears; Ctrl+C/V/X copies/pastes compatibly with Excel and Google Sheets; Ctrl+Z/Y undoes/redoes; Space selects the row. On a header Enter sorts, Alt+↓ opens the menu, Alt+←/→ changes width, Alt+Shift+←/→ changes order. In trees and groups ←/→ collapses/expands.
  • Mobile: On touch, rows are taller, menus open from the bottom, a long press opens the context menu (copy, edit…). On a narrow screen, pinning is removed automatically if pinned columns take most of the area.
  • Accessibility: ARIA grid/treegrid pattern; row/column counts, sorting, selection and expanded states are announced; result count, copy and paste are read from a live region.
  • RTL: Inside dir="rtl", pinned columns, arrows and resizing flip direction.
DataGrid(props: DataGridProps<T>): JSX.Element

Examples

"use client";
const [rows, setRows] = useState(orders);

<DataGrid
  title="Orders"
  rows={rows}
  rowKey="id"
  selection="multiple"
  storageKey="orders"
  columns={[
    { key: "no", header: "No", width: 90, pinned: "start" },
    { key: "customer", header: "Customer", flex: 1, editable: true, validate: (v) => (v ? null : "Required") },
    { key: "status", header: "Status", type: "select", options: ["New", "Shipped", "Delivered"], editable: true },
    { key: "amount", header: "Amount", format: "currency", aggregate: "sum", editable: true },
    { key: "date", header: "Date", format: "date" },
  ]}
  onCellsChange={(changes) =>
    setRows((old) => old.map((r) => {
      const own = changes.filter((c) => c.rowKey === r.id);
      return own.length ? Object.assign({ ...r }, ...own.map((c) => ({ [c.key]: c.value }))) : r;
    }))
  }
  pagination={{ pageSize: 50, pageSizeOptions: [25, 50, 100] }}
/>

DataGrid pagination prop: PaginationProps without total.

type DataGridPagination = Omit<PaginationProps, "total" | "href" | "searchParams">

Parts of the DataGrid toolbar.

NameTypeDefaultDescription
search?booleantrueGlobal search box.
columns?booleantrueShow/hide columns panel.
density?booleantrueDensity picker.
export?booleantrueCSV download button.

Classes added to the inner parts of DataGrid.

NameTypeDescription
toolbar?stringToolbar.
viewport?stringScrolled area.
header?stringHeader row.
row?stringEach data row.
cell?stringEach cell.
footer?stringFooter totals row.
statusBar?stringStatus bar (record count, pagination).

DataGridProps

interface

Props of the DataGrid component.

NameTypeDefaultDescription
columnsreadonly DataGridColumn<T>[]Columns. See DataGridColumn.
rowsreadonly T[]Rows. For tree data, only the root nodes.
rowKey?keyof T | ((row: T) => DataGridKey)Unique key of the row: a field name or a function. If omitted, the id field is used, or the index if that is missing too (give a key for editing and selection).
label?stringScreen reader name of the table. Give it when there is no visible title.
title?ReactNodeTitle at the start of the toolbar.
actions?ReactNodeYour own buttons appended to the end of the toolbar.
toolbar?boolean | DataGridToolbartrueToolbar. false hides it; an object selects the parts. See DataGridToolbar.
height?number | stringHeight (e.g. 600, "70vh", "100%"). If omitted, it grows with the content and stops at maxHeight.
maxHeight?number | string"min(70vh, 40rem)"Maximum height when height is not given.
density?DataGridDensityRow density. Fully controlled when given together with onDensityChange; given alone, it acts like an initial value (returns to it when the prop changes) and the toolbar density menu still works.
defaultDensity?DataGridDensity"standard"Initial density. If omitted, the level closest to the UIProvider density setting is used.
onDensityChange?(density: DataGridDensity) => voidCalled when the density changes.
rowHeight?numberRow height (px); overrides density.
gridLines?"horizontal" | "both" | "none""horizontal"Cell borders.
striped?booleanfalseAlternate rows are lightly tinted.
sort?DataGridSortSorting (controlled). See DataGridSort.
defaultSort?DataGridSortInitial sorting.
onSortChange?(sort: DataGridSort) => voidCalled when sorting changes.
multiSort?booleantrueSort by multiple columns with Shift.
filters?DataGridFiltersFilters (controlled). See DataGridFilters.
defaultFilters?DataGridFiltersInitial filters.
onFiltersChange?(filters: DataGridFilters) => voidCalled when filters change.
search?stringGlobal search text (controlled).
defaultSearch?stringInitial search text.
onSearchChange?(search: string) => voidCalled when the search text changes.
columnState?DataGridColumnStateColumn layout (controlled). See DataGridColumnState.
defaultColumnState?DataGridColumnStateInitial column layout.
onColumnStateChange?(state: DataGridColumnState) => voidCalled when the user changes the column layout.
storageKey?stringIf given, the column layout and density are stored in the browser under this name; the user's layout comes back after a page reload.
selection?"none" | "single" | "multiple""none"Row selection. "multiple" adds a checkbox column (range with Shift); "single" selects on row click.
selectedKeys?readonly DataGridKey[]Keys of the selected rows (controlled).
defaultSelectedKeys?readonly DataGridKey[]Initially selected rows.
onSelectionChange?(keys: DataGridKey[], rows: T[]) => voidCalled with the keys and rows when the selection changes.
isRowSelectable?(row: T) => booleanCan the row be selected?
groupable?booleanfalseEnables grouping: group by dragging headers to the grouping bar above or from the column menu.
groupBy?readonly string[]Grouped columns, in order (controlled).
defaultGroupBy?readonly string[]Initially grouped columns.
onGroupByChange?(groupBy: string[]) => voidCalled when grouping changes.
getChildren?(row: T) => readonly T[] | undefinedTree data: the child rows of a row. If given, the grid becomes a tree table (role="treegrid"); the tree column is drawn indented with a toggle button.
loadChildren?(row: T) => Promise<readonly T[]>Loads child rows on first expand (e.g. from a server). Called for nodes where getChildren returns undefined.
hasChildren?(row: T) => booleanWith loadChildren: can the node have child rows? If omitted, all can be expanded.
treeColumn?stringFirst visible columnColumn where the tree indent is drawn.
expandedKeys?readonly DataGridKey[]Expanded tree nodes (controlled).
defaultExpandedKeys?readonly DataGridKey[]Initially expanded tree nodes.
onExpandedChange?(keys: DataGridKey[]) => voidCalled when a tree node is expanded or collapsed.
renderDetail?(row: T) => ReactNodeDetail panel opened under the row. If given, a toggle column is added.
detailHeight?number160Default height (px) until the detail panel is measured.
onCellsChange?(changes: DataGridCellChange<T>[]) => unknownCalled with the list of changes when cells are edited (typing, pasting, clearing, undo); you update the rows. If it returns a Promise the cell shows as "saving"; if it rejects, the value is reverted and the error is shown.
onRowClick?(row: T, event: MouseEvent<HTMLElement>) => voidCalled when a row is clicked.
onRowDoubleClick?(row: T, event: MouseEvent<HTMLElement>) => voidCalled when a row is double-clicked (if no cell is being edited).
getRowClassName?(row: T) => string | undefinedClasses added to the row.
onRowReorder?(row: T, target: T, position: "before" | "after") => voidReorder rows by dragging: a handle column is added. On drop, called with the moved row, the target row and the position. Disabled while grouping.
contextMenu?false | ((context: DataGridContextMenuContext<T>) => readonly MenuEntry[])Right-click (long press on touch) menu. The function returns its own items; built-in items (copy, paste, clear…) are appended below. false disables the menu.
mode?"client" | "server""client"Where the data is processed. "server": no sorting, filtering, search or pagination is done; changes are reported via on…Change, and you pass the rows from the server in rows.
rowCount?numberTotal record count in server mode (pagination and status bar).
loading?booleanLoading indicator (thin bar on top; skeleton when there are no rows).
onLoadMore?() => voidInfinite scroll: called when nearing the end. Give it together with hasMore.
hasMore?booleanAre there more rows to load?
pagination?boolean | DataGridPaginationPagination at the bottom. true enables it with default settings; an object takes PaginationProps settings (page size, options…). In client mode the grid paginates; in server mode give rowCount.
footer?booleantrueFooter totals row (if columns have aggregate).
statusBar?booleantrueStatus bar (record and selection counts).
empty?ReactNodeContent shown when there are no rows.
locale?stringLocale used for formatting. Defaults to the UIProvider's locale.
currency?stringCurrency. Defaults to the UIProvider's currency.
exportFileName?stringName of the CSV file (without extension). Defaults to messages.exportFileName ("tablo").
messages?Partial<DataGridMessages>Texts of this table; for the whole app use the ui.dataGrid namespace of the dictionary. See DataGridMessages.
apiRef?Ref<DataGridApi<T>>Functions callable from outside. See DataGridApi.
className?stringClasses added to the root element.
classNames?DataGridClassNamesClasses added to the inner parts.

Row key.

type DataGridKey = string | number

Data type of a column. Decides the filter operators, the editor, alignment, how pasted text is parsed and sorting.

  • "text": Text (default).
  • "number": Number; automatic when format is number | currency | percent.
  • "date": Date (Date or ISO string); automatic when format is date | datetime.
  • "boolean": Yes/No; drawn as a checkbox.
  • "select": A value from options.
type DataGridColumnType = "text" | "number" | "date" | "boolean" | "select"

DataGrid column. For shared fields see DataGridColumn in core.

Extends: Core.DataGridColumn<T, ReactNode, TooltipProp>

NameTypeDescription
cellClassName?string | ((row: T, value: unknown) => string | undefined)Classes added to the cell; with a function, based on the row and value.
headerClassName?stringClasses added to the header cell.

An option of a "select" column.

NameTypeDescription
valuestringValue stored in the row.
label?stringDisplay name.

Built-in aggregation functions.

type DataGridAggregateName = "sum" | "avg" | "min" | "max" | "count"

Where the context menu was opened.

type DataGridContextMenuContext = Core.DataGridContextMenuContext<T, DataGridColumn<T>>

Aggregation of a column: shown in group rows and the summary row. A built-in name or a (values, rows) => result function.

type DataGridAggregate = DataGridAggregateName | ((values: unknown[], rows: readonly T[]) => unknown)

Info passed to the DataGridColumn render function.

NameTypeDescription
rowTRow.
valueunknownRaw value of the cell (value or row[key]).
textstringFormatted text (format applied).
rowKeyDataGridKeyKey of the row.
depthnumberDepth of the row in tree data (root is 0).

Info passed to the DataGridColumn editor function.

NameTypeDescription
rowTRow being edited.
valueunknownCurrent value in the editor.
onChange(value: unknown) => voidChanges the value (does not save yet).
commit(value?: unknown) => voidSaves the value and leaves editing. When a value is given, it is set first. When validation fails, editing continues.
cancel() => voidDrops the change and leaves editing.
errorstring | nullValidation error (if any).
typedbooleanEditing started by pressing a letter (the value was replaced by that letter).
inputProps{ autoFocus: true; "aria-label": string; "aria-invalid": boolean | undefined; }Id and ARIA props to pass to the editor.

Sorting of one column.

NameTypeDescription
keystringThe column's key.
direction"asc" | "desc"Direction.

Sorting: columns in priority order. Shift-clicking a header adds a second, third column.

type DataGridSort = readonly DataGridSortItem[]

Filter operator.

  • Text: contains, notContains, equals, notEquals, startsWith, endsWith
  • Number and date: equals, notEquals, gt, gte, lt, lte, between
  • Select, yes/no and value list: in
  • All: empty, notEmpty
type DataGridFilterOperator = "contains" | "notContains" | "equals" | "notEquals" | "startsWith" | "endsWith" | "gt" | "gte" | "lt" | "lte" | "between" | "in" | "empty" | "notEmpty"

Filter of one column.

NameTypeDescription
operatorDataGridFilterOperatorOperator.
value?unknownValue. An array of values for in; a "2026-10-30" string for dates.
value2?unknownUpper bound of the between operator.

Filters by column key.

type DataGridFilters = Readonly<Record<string, DataGridFilter>>

Column layout changed by the user. Can be stored in the browser with storageKey or kept on your side with columnState.

NameTypeDescription
order?readonly string[]Order of column keys. Missing ones are appended.
widths?Readonly<Record<string, number>>Widths set by hand (px).
pinned?Readonly<Record<string, "start" | "end" | null>>Pins; null removes the column's own pinned.
hidden?Readonly<Record<string, boolean>>Hidden columns; false removes the column's own hidden.

Row density.

type DataGridDensity = "compact" | "standard" | "comfortable"

A cell change.

NameTypeDescription
rowTThe changed row (before the change).
rowKeyDataGridKeyKey of the row.
keystringThe column's key.
valueunknownNew value.
oldValueunknownOld value.

The component's own texts; to translate into another language.

NameTypeDefaultDescription
emptystring"Kayıt yok"
noResultsstring"Filtreye uyan kayıt yok"
searchstring"Tabloda ara…"
columnsstring"Sütunlar"
densitystring"Yoğunluk"
compactstring"Sıkışık"
standardstring"Normal"
comfortablestring"Geniş"
exportstring"CSV indir"
sortAscstring"Artan sırala"
sortDescstring"Azalan sırala"
clearSortstring"Sıralamayı kaldır"
filterstring"Filtrele…"
clearFilterstring"Filtreyi kaldır"
clearAllFiltersstring"Tüm filtreleri kaldır"
pinStartstring"Başa sabitle"
pinEndstring"Sona sabitle"
unpinstring"Sabitlemeyi kaldır"
groupBystring"Bu sütuna göre grupla"
ungroupstring"Gruplamayı kaldır"
autosizestring"Genişliği içeriğe sığdır"
autosizeAllstring"Tüm sütunları sığdır"
hidestring"Sütunu gizle"
showAllstring"Tümünü göster"
resetstring"Sıfırla"
copystring"Kopyala"
copyWithHeadersstring"Başlıklarla kopyala"
pastestring"Yapıştır"
clearstring"Hücreleri temizle"
editstring"Düzenle"
undostring"Geri al"
redostring"Yinele"
selectAllstring"Tümünü seç"
selectRowstring"Satırı seç"
expandstring"Aç"
collapsestring"Kapat"
expandAllstring"Tümünü aç"
collapseAllstring"Tümünü kapat"
groupBarHintstring"Gruplamak için sütun başlığını buraya sürükleyin"
rowsstring"kayıt"
selectedstring"seçili"
operatorstring"Koşul"
valuestring"Değer"
fromstring"En az"
tostring"En çok"
yesstring"Evet"
nostring"Hayır"
totalstring"Toplam"
columnMenustring"Sütun menüsü"
dragRowstring"Satırı taşı"
loadingstring"Yükleniyor"
savingstring"Kaydediliyor"
sortedAscstring"artan sıralandı"
sortedDescstring"azalan sıralandı"
copiedstring"hücre kopyalandı"
pastedstring"hücre yapıştırıldı"
pasteSkippedstring"hücre geçersiz olduğu için atlandı"
sharestring"Dışa aktar"Export (React Native: share sheet).
moveLeftstring"Sola taşı"Moves the column one to the left.
moveRightstring"Sağa taşı"
moveUpstring"Yukarı taşı"Moves the row one up (screen reader).
moveDownstring"Aşağı taşı"
addSortstring"Sıralamaya ekle"Adds the column to the sort in multi-sort.
applystring"Uygula"Confirm button of the filter panel.
detailsstring"Ayrıntı"Row detail.
invalidValuestring"Geçersiz değer"When an edited cell's value can't be read for its column type.
exportFileNamestring"tablo"Default name of the exported CSV file (without extension).
operatorsRecord<DataGridFilterOperator, string>Names of the filter operators.
aggregatesRecord<DataGridAggregateName, string>Names of the aggregation functions.

DataGridApi

interface

Functions of the DataGrid callable from outside (apiRef).

NameTypeDescription
getVisibleRows() => T[]Visible (filtered, sorted) rows. Expanded tree rows included.
getSelectedRows() => T[]Selected rows.
exportCsv(options?: { fileName?: string; rows?: "all" | "selected"; }) => voidDownloads a CSV file. rows: "selected" writes only the selected rows, "all" (default) all filtered rows (all pages).
getCsv(options?: { rows?: "all" | "selected"; }) => stringReturns the CSV text (without downloading).
scrollToRow(key: DataGridKey) => voidScrolls a row into view and focuses it.
startEdit(key: DataGridKey, column: string) => voidOpens a cell for editing.
resetColumns() => voidResets the column layout (order, width, pinning, visibility).
expandAll() => voidExpands all groups and tree nodes.
collapseAll() => voidCollapses all groups and tree nodes.