DataGridProps
DataGridProps
Section titled “DataGridProps”Complete API reference for the DataGrid component props.
Type Definition
Section titled “Type Definition”interface DataGridProps<T> { // Required data: T[]; columns: ColumnDef<T>[]; rowKey: keyof T | ((row: T) => string);
// Display emptyMessage?: string; compact?: boolean; className?: string; stickyHeader?: boolean; virtualize?: boolean | 'auto'; rowHeight?: number;
// Filtering showFilter?: boolean; filterPlaceholder?: string; filterFields?: (keyof T)[];
// Flash disableFlash?: boolean;
// Column Resizing resizable?: boolean; columnWidths?: Record<string, number>; onColumnResize?: (field: string, width: number) => void; minColumnWidth?: number; maxColumnWidth?: number;
// Column Reordering reorderable?: boolean; columnOrder?: string[]; onColumnReorder?: (newOrder: string[]) => void;
// Events onRowClick?: (row: T) => void;}Required Props
Section titled “Required Props”data: T[]Array of data objects to display. Each object represents one row.
const users = [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' },];
<DataGrid data={users} ... />columns
Section titled “columns”columns: ColumnDef<T>[]Array of column definitions. See ColumnDef for details.
const columns = [ { field: 'name', header: 'Name' }, { field: 'email', header: 'Email' },];rowKey
Section titled “rowKey”rowKey: keyof T | ((row: T) => string)Unique identifier for each row. Used for React keys and change detection.
// Field name<DataGrid rowKey="id" ... />
// Function<DataGrid rowKey={(row) => `${row.type}-${row.id}`} ... />Display Props
Section titled “Display Props”emptyMessage
Section titled “emptyMessage”emptyMessage?: string// Default: 'No data'Message shown when data array is empty or all rows are filtered out.
compact
Section titled “compact”compact?: boolean// Default: falseReduces row height for dense displays.
className
Section titled “className”className?: stringAdditional CSS class for the grid container.
stickyHeader
Section titled “stickyHeader”stickyHeader?: boolean// Default: trueMakes the header row sticky during scroll.
virtualize
Section titled “virtualize”virtualize?: boolean | 'auto'// Default: 'auto'Controls virtualization behavior:
true: Always virtualizefalse: Never virtualize'auto': Virtualize when rows > 100
rowHeight
Section titled “rowHeight”rowHeight?: number// Default: 36Row height in pixels. Important for accurate virtualization calculations.
Filter Props
Section titled “Filter Props”showFilter
Section titled “showFilter”showFilter?: boolean// Default: falseShows a filter input above the grid.
filterPlaceholder
Section titled “filterPlaceholder”filterPlaceholder?: string// Default: 'Filter...'Placeholder text for the filter input.
filterFields
Section titled “filterFields”filterFields?: (keyof T)[]// Default: all columnsLimits which fields are searched during filtering.
<DataGrid filterFields={['name', 'email']} // Only search name and email .../>Flash Props
Section titled “Flash Props”disableFlash
Section titled “disableFlash”disableFlash?: boolean// Default: falseDisables all flash highlighting effects.
Column Resize Props
Section titled “Column Resize Props”resizable
Section titled “resizable”resizable?: boolean// Default: falseEnables column resizing by dragging column borders.
columnWidths
Section titled “columnWidths”columnWidths?: Record<string, number>Controlled column widths. Keys are field names, values are pixel widths.
const [widths, setWidths] = useState({ name: 200, email: 300 });
<DataGrid columnWidths={widths} onColumnResize={(field, width) => setWidths(prev => ({ ...prev, [field]: width })) } .../>onColumnResize
Section titled “onColumnResize”onColumnResize?: (field: string, width: number) => voidCallback when a column is resized. Receives field name and new width.
minColumnWidth
Section titled “minColumnWidth”minColumnWidth?: number// Default: 50Minimum width in pixels for all columns.
maxColumnWidth
Section titled “maxColumnWidth”maxColumnWidth?: number// Default: 500Maximum width in pixels for all columns.
Column Reorder Props
Section titled “Column Reorder Props”reorderable
Section titled “reorderable”reorderable?: boolean// Default: falseEnables column reordering via drag and drop.
columnOrder
Section titled “columnOrder”columnOrder?: string[]Controlled column order. Array of field names in display order.
const [order, setOrder] = useState(['name', 'email', 'age']);
<DataGrid columnOrder={order} onColumnReorder={setOrder} .../>onColumnReorder
Section titled “onColumnReorder”onColumnReorder?: (newOrder: string[]) => voidCallback when columns are reordered. Receives new order array.
Event Props
Section titled “Event Props”onRowClick
Section titled “onRowClick”onRowClick?: (row: T) => voidCallback when a row is clicked. Receives the row data object.
<DataGrid onRowClick={(user) => { console.log('Clicked:', user); navigate(`/users/${user.id}`); }} .../>Generic Type Parameter
Section titled “Generic Type Parameter”The DataGrid component is generic over the data type:
interface User { id: number; name: string; email: string;}
// Explicit type parameter<DataGrid<User> data={users} columns={columns} rowKey="id" />
// Inferred from data prop<DataGrid data={users} columns={columns} rowKey="id" />The type parameter enables:
- Type-safe
rowKey - Type-safe column
fieldvalues - Type-safe formatter and cellClass callbacks
- Type-safe
onRowClickhandler