DataGridComponent
The grid component: columns, data, borders, resizing, and reordering.
DataGridComponent takes a set of columns and a data source and renders a grid. Resizing and reordering are opt-in — enable them per grid with resizableColumns and reorderableColumns, or per column via each column's own resizable and reorderable fields.
Resizable, reorderable columns
DataGridComponent
Live exampleimport { useState } from "react";
import { defineColumnsFromRows } from "@gridkitjs/core";
import {
DataGridComponent,
type ColumnDefinition,
type ResizeMode,
} from "@gridkitjs/react";
const columns: readonly ColumnDefinition<Row>[] = [
...defineColumnsFromRows(rows),
{
field: "Cost",
id: "Cost.currency",
type: "currency",
headerTemplate: <span className="italic">Cost</span>,
cellTemplate: ({ value, row }) => (
<span className={row.Cost > 500 ? "font-semibold text-red-600" : ""}>
{currency.format(Number(value))}
</span>
),
},
];
const [resizeMode, setResizeMode] = useState<ResizeMode>("fit");
<DataGridComponent
columns={columns}
dataSource={rows}
borders="all"
resizableColumns
reorderableColumns
resizeMode={resizeMode}
/>;Props
Keyboard & pointer interactions
- Drag a header's trailing edge to resize; double-click it to size the column to its content.
- With the resize handle focused, arrow keys nudge the width; Escape cancels an in-progress resize.
- Drag a header to reorder columns.
- With a header focused, Ctrl+ArrowLeft / Ctrl+ArrowRight reorders it via keyboard; Escape cancels an in-progress drag.