@reactloom/data-grid
v1.3.0
Published
Accessible React data grid, pivot table and spreadsheet for ReactLoom: keyboard navigation, sorting, filtering, pagination, selection, column resizing, server-side data and row virtualization.
Maintainers
Readme
@reactloom/data-grid
An accessible data grid for ReactLoom: role="grid" keyboard navigation, sorting, search,
pagination, row selection, cell editing, grouping with totals, CSV export, resizable and
hideable columns, and row virtualization.
pnpm add @reactloom/data-grid @reactloom/ui @reactloom/themeimport '@reactloom/data-grid/styles.css';
import { DataGrid } from '@reactloom/data-grid';
<DataGrid
aria-label="Invoices"
columns={[{ key: 'customer', header: 'Customer', sortable: true }, { key: 'amount', header: 'Amount', align: 'end' }]}
rows={invoices}
getRowId={(r) => r.id}
pageSize={25}
/>;- Editing:
editable,editor: 'text' | 'number' | 'select' | custom,validate; Enter, F2 or typing starts, Enter saves, Escape cancels.onCellEditmay return a promise. - Grouping:
groupBy="status"withaggregate: 'sum' | 'avg' | 'min' | 'max' | 'count'. - Multi-sort: supply
defaultSortsor controlledsortsandonSortsChange. Put the primary sort first. Shift + click or Shift + Enter/Space updates a column without clearing the others. - Column filters: pass
filtersordefaultFilterswith typed text, number, date, boolean or empty rules. Every rule must match. Date rules use epoch milliseconds againstDatevalues. UseapiRef.current.setFilters([])to clear an uncontrolled grid. SetmanualFilteringandmanualSortingwhen your server owns the query, and pass the server’s total with manual pagination. - Export:
apiRef.current.downloadCsv('orders.csv')saves the filtered, sorted view;toCsv(columns, rows)works anywhere. Formula-like text is neutralised (CSV injection).
Built on TanStack Table and TanStack Virtual; the public API is ReactLoom's own. For simple,
read-only data use Table from @reactloom/ui instead.
Column layouts and Excel export
Pass columnLayout or defaultColumnLayout with ordered keys and logical
pinnedStart / pinnedEnd groups. Enable reorderableColumns to move a header
within its group with Alt + Shift + an arrow key. Save a layout in your app
using getColumnLayout() and restore it with setColumnLayout(layout).
For a full saved view, use getView() and restoreView(view) on the grid API.
The versioned snapshot includes the layout, widths, visibility, filters, search,
sorts, and grouping. Store it in your application and pass change handlers for
controlled settings you want to restore.
Load toXlsx or downloadXlsx from @reactloom/data-grid/xlsx when export is
requested. Pass getExportColumns() and getRows(scope) to export the visible
columns in display order. The single worksheet uses typed numbers and booleans,
ISO text for dates, and literal text for strings.
Server data source
Import useDataGridDataSource from @reactloom/data-grid/server. It loads the active
offset and limit with your search, column filters, and sort priorities. Pass its
rows, rowCount, and loading to a grid using manual sorting, filtering, and
pagination. Keep the loader identity stable and forward its signal to fetch.
Use refresh() to clear cached ranges and reload the active page.
Documentation and live examples: https://www.reactloom.dev/components/data-grid · https://www.reactloom.dev/components/pivot-table · https://www.reactloom.dev/components/spreadsheet
