Column definitions

Inferring columns from row data with defineColumnsFromRows.

defineColumnsFromRows inspects your row data and infers a type and alignment per field, one level into nested objects. Use it as a starting point, then override or extend individual columns.

Column definition shape

PropTypeDefaultDescription
fieldFieldPath<Row> | string

Path to this column's value, e.g. "Application.Id".

idstring

Stable identity for sizing/order state. Defaults to field.

headerTemplateNode | (() => Node)

Header content, or a function returning it at render time.

cellTemplate(context: CellTemplateContext<Row>) => Node

Renders this column's cells in place of the raw value.

typeColumnType

The value type of this column's cells, e.g. "currency".

alignment"left" | "center" | "right"

Alignment of this column's cells. Falls back to type.

widthnumber

Width in px this column starts at.

minWidthnumber

Lower bound a resize may not drag below.

maxWidthnumber

Upper bound a resize may not drag above.

resizableboolean

Whether this column can be resized, overriding the grid-level default.

reorderableboolean

Whether this column can be dragged to a new position, overriding the grid-level default.

wrap{ header?, cells? }

Lets this column's header and/or cell text wrap onto multiple lines instead of truncating.

headerClassNamestring

Extra class names appended to this column's th.

cellClassNamestring

Extra class names appended to this column's td, on every row.

Inferred columns

defineColumnsFromRows

Live example
IdServiceEnvironment NameEnvironment RegionStatusCost
1checkout-apiproductionus-east-1healthy1240.5
2billing-workerproductioneu-west-1degraded860.2
3search-indexstagingus-east-1healthy92.75
4notificationsproductionus-west-2down305.4
5analytics-pipelinestagingeu-west-1healthy145
import { defineColumnsFromRows } from "@gridkitjs/core";
import { DataGridComponent } from "@gridkitjs/react";

const columns = defineColumnsFromRows(rows);

<DataGridComponent columns={columns} dataSource={rows} borders="horizontal" />;
PropTypeDefaultDescription
defineColumnsFromRows(rows)readonly ColumnDefinition<Row>[]

Infers a type and alignment per field, one level into nested objects.

accessDotted(obj, path)unknown

Reads a value at a dotted path, e.g. "Application.Id".

alignmentForType(type)ColumnAlignment

Alignment a column type defaults to — "right" for numbers.

resolveColumnLabel(column)string

The label a column's header falls back to when it sets no headerTemplate.