To display data, use the DataEditor component. You must import the mandatory CSS and provide getCellContent, columns, and rows props.
Note: getCellContent is a function that receives [col, row] and returns a GridCell object.
import DataEditor, { GridCell, GridCellKind, Item } from "@glideapps/glide-data-grid";
import "@glideapps/glide-data-grid/dist/index.css";
// 1. Define columns
const columns = [
{ title: "First Name", width: 100 },
{ title: "Last Name", width: 100 },
];
// 2. Provide data via getCellContent
function getData([col, row]: Item): GridCell {
const person = data[row];
if (col === 0) {
return {
kind: GridCellKind.Text,
data: person.firstName,
allowOverlay: false,
displayData: person.firstName,
};
} else if (col === 1) {
return {
kind: GridCellKind.Text,
data: person.lastName,
allowOverlay: false,
displayData: person.lastName,
};
} else {
throw new Error();
}
}
// 3. Render the component
<DataEditor getCellContent={getData} columns={columns} rows={numRows} />