View as Markdown

Columns

Columns

Column definitions, widths, alignment, types and formats, visibility, resizing, reordering and auto-size.

Columns are plain definition objects, passed as the columns array or as <DataGridColumn> children (nested children form stacked headers). Each one is compiled once per stable definition and addressed by a stable column id (its id, else its field), so state such as width, order and visibility survives data changes.

Defining columns

A column reads a row field or computes its value from the row. Widths accept pixels, percentages of the viewport and auto, with minimum and maximum bounds that also clamp resizing. Cell and header text align with logical directions, so alignment mirrors in RTL.

Typed columns format numbers, currency, percentages and dates through the platform Intl API using the grid locale, currency and time zone. Boolean columns can render as checkboxes. Overflowing text is clipped, truncated with an ellipsis, or truncated with a tooltip (overflow: 'clip' | 'ellipsis' | 'ellipsisWithTooltip'). A primaryKey column derives the stable row id.

import { DataGrid, type DataGridColumn } from '@salmonui/data-grid';
import '@salmonui/data-grid/styles.css';

const columns: DataGridColumn<Order>[] = [
  { field: 'id', header: 'Order', type: 'number', primaryKey: true, width: 100 },
  { field: 'customer.name', header: 'Customer', width: '30%', minWidth: 160 },
  { field: 'total', header: 'Total', type: 'number', format: 'C2', align: 'end' },
  { id: 'net', header: 'Net', valueGetter: (row) => row.total - row.tax, type: 'number' },
  { field: 'shipped', header: 'Shipped', type: 'boolean', displayAsCheckbox: true },
];

<DataGrid data={orders} columns={columns} locale="en-US" currency="USD" timeZone="UTC" aria-label="Orders" />

Column definitions

Open demo

Fields and header text, px / percent / auto widths with min and max, alignment, typed and formatted values, checkbox display, computed values and overflow modes, declared as <DataGridColumn> children.

Order
Customer
Country
Qty
Unit price
Discount
Placed
Shipped
Line total
Note (ellipsis with tooltip)
Product (clip)
ORD-10000
Dewi Lestari
Malaysia
9
$129.00
15%
Sep 21, 2026
$1,161.00
Grinder
ORD-10001
Bao Nguyen
France
5
$12.75
0%
Nov 22, 2026
$63.75
Oolong tea
ORD-10002
Bao Nguyen
France
4
$14.00
5%
Dec 11, 2026
$56.00
Filter beans
ORD-10003
Aiko Tan
Japan
7
$64.90
5%
May 13, 2026
$454.30
Kettle
ORD-10004
Chen Wei
France
7
$42.00
10%
Oct 24, 2026
$294.00
Leave the parcel with the building reception if nobody answers the door.
Pour-over kit
ORD-10005
Elif Kaya
France
10
$64.90
15%
Apr 18, 2026
$649.00
Leave the parcel with the building reception if nobody answers the door.
Kettle
ORD-10006
Bao Nguyen
France
9
$129.00
10%
Jun 11, 2026
$1,161.00
Gift wrap
Grinder
ORD-10007
Elif Kaya
Germany
10
$18.50
0%
Mar 27, 2026
$185.00
Espresso beans
ORD-10008
Bao Nguyen
Portugal
6
$9.25
15%
Oct 23, 2026
$55.50
Gift wrap
Green tea
ORD-10009
Bao Nguyen
France
12
$9.25
15%
Feb 12, 2026
$111.00
Green tea
ORD-10010
Hana Sato
Germany
10
$12.75
10%
Aug 8, 2026
$127.50
Oolong tea
ORD-10011
Dewi Lestari
Germany
9
$9.25
10%
Jan 26, 2026
$83.25
Leave the parcel with the building reception if nobody answers the door.
Green tea
ORD-10012
Chen Wei
Portugal
7
$129.00
5%
Apr 26, 2026
$903.00
Call before delivery
Grinder
ORD-10013
Bao Nguyen
Malaysia
1
$64.90
15%
Feb 21, 2026
$64.90
Gift wrap
Kettle
ORD-10014
Hana Sato
Germany
12
$9.25
10%
May 24, 2026
$111.00
Call before delivery
Green tea
ORD-10015
Farah Aziz
Japan
1
$9.25
5%
Jan 15, 2026
$9.25
Green tea
ORD-10016
Aiko Tan
Malaysia
12
$14.00
5%
Feb 3, 2026
$168.00
Filter beans
ORD-10017
Farah Aziz
France
9
$18.50
10%
Jul 20, 2026
$166.50
Espresso beans
ORD-10018
Chen Wei
France
1
$64.90
5%
Jan 18, 2026
$64.90
Gift wrap
Kettle
ORD-10019
Goran Petrov
France
9
$12.75
0%
Jun 24, 2026
$114.75
Leave the parcel with the building reception if nobody answers the door.
Oolong tea

Dates are formatted on the server as well as in the browser, so a server rendered grid must pin the time zone and locale; otherwise the two outputs differ and hydration fails.

Array or children, inferred types and column ids

The columns array and <DataGridColumn> children take the same fields and compile to the same stable columns; pass one form (with both, the children win and development builds warn).

Without type, a column infers it from the first non-null value of its field: number, boolean, string or date. Rows that arrive later resolve a pending type without recompiling the columns. When no value decides the type, the column falls back to string with a development warning; set type to silence it.

A column id resolves from column.id, then column.field; a column with neither, such as a template-only column, gets a deterministic generated id (__col_<position>, identical on the server and the client) and a development warning, and a duplicate id gets a ~2 suffix. Give such columns an id so state, events and methods can address them.

The instance reads the compiled columns:

Method Returns
api.getColumn(fieldOrId) The column with that id, else the first with that field
api.getColumns() Every leaf column in definition order, hidden ones included
api.getVisibleColumns() / api.getHiddenColumns() Visible leaves in runtime order / hidden leaves
api.getColumnAt(index) The visible leaf at an index (getColumnByIndex)
api.getColumnIndex(fieldOrId) Its index among the visible leaves, or -1

Text, markup and templates

Cell text is always text: React escapes it, so a value such as <b>Aiko Tan</b> shows its angle brackets and can never inject markup. There is no switch that renders cell values as HTML: it would add a per-cell branch and an XSS footgun for no capability gain. Return elements from column.renderCell instead of building HTML strings; for trusted HTML the application owns the dangerouslySetInnerHTML call inside its template.

Templates are functions only: there are no ${field} string templates. column.renderCell(ctx) and column.renderHeader(ctx) receive the row, value and formatted value and return React content. Functions are type-checked, need no template compiler (string evaluation breaks a strict CSP), and keep untrusted data out of HTML parsing. For example, renderCell: ({ row }) => <b>{row.Name}</b>. See Templates for every template hook.

Column types, ids and reading methods

Open demo

Columns without type infer it from the first non-null value, ids resolve from id, then field, then a generated id with a warning, the same columns work as an array or as <DataGridColumn> children, text that looks like markup stays text, a function template renders rich content, and the column reading methods report ids and visible positions.

Order
Customer
Qty
Placed
Shipped
Markup as text
Status
ORD-10000
Aiko Tan
7
Nov 25, 2026
true
<b>Aiko Tan</b>
Shipped
ORD-10001
Hana Sato
9
Mar 23, 2026
true
<b>Hana Sato</b>
Shipped
ORD-10002
Bao Nguyen
5
Nov 4, 2026
true
<b>Bao Nguyen</b>
Shipped
ORD-10003
Farah Aziz
8
Jun 4, 2026
true
<b>Farah Aziz</b>
Shipped
ORD-10004
Goran Petrov
6
May 8, 2026
false
<b>Goran Petrov</b>
Open
ORD-10005
Chen Wei
12
Aug 14, 2026
true
<b>Chen Wei</b>
Shipped
ORD-10006
Jun Park
4
Aug 28, 2026
true
<b>Jun Park</b>
Shipped
ORD-10007
Chen Wei
11
Oct 1, 2026
true
<b>Chen Wei</b>
Shipped
ORD-10008
Aiko Tan
2
Feb 10, 2026
false
<b>Aiko Tan</b>
Open
ORD-10009
Dewi Lestari
1
Aug 25, 2026
false
<b>Dewi Lestari</b>
Open
ORD-10010
Chen Wei
2
Feb 6, 2026
false
<b>Chen Wei</b>
Open
ORD-10011
Farah Aziz
6
Mar 16, 2026
false
<b>Farah Aziz</b>
Open
ORD-10012
Hana Sato
2
Mar 5, 2026
false
<b>Hana Sato</b>
Open
ORD-10013
Jun Park
12
Jul 6, 2026
false
<b>Jun Park</b>
Open
ORD-10014
Aiko Tan
8
Feb 27, 2026
true
<b>Aiko Tan</b>
Shipped
ORD-10015
Hana Sato
3
Jan 28, 2026
false
<b>Hana Sato</b>
Open
ORD-10016
Farah Aziz
3
Aug 4, 2026
true
<b>Farah Aziz</b>
Shipped
ORD-10017
Jun Park
12
Jan 15, 2026
false
<b>Jun Park</b>
Open
ORD-10018
Chen Wei
5
Jul 1, 2026
false
<b>Chen Wei</b>
Open
ORD-10019
Goran Petrov
5
Feb 24, 2026
false
<b>Goran Petrov</b>
Open

Press Read columns.

Capability flags, locked and identity columns

Data Grid-wide features turn on with sorting, filtering, search, grouping, editing, resizable and reorderable; a column turns its part off with sortable, filterable, searchable, groupable, editable, resizable or reorderable set to false. The flags are enforced by the core, so methods respect them as well as the header, filter bar, search box and menus.

column.lockPosition keeps a column first in its pinned zone: it cannot be reordered, and no other column can move before it. column.identity (isIdentity) marks a key the server generates; it defaults editable to false.

Column capabilities, locked and identity columns

Open demo

Sorting, filtering, search, grouping, editing, resizing and reordering on for the grid and turned off per column with sortable, filterable, searchable, groupable, editable, resizable and reorderable; a lockPosition first column and an identity key column.

Drag a column header here to group by that column
Order
Customer (not sortable, not searchable)
Country (not filterable)
Category (not groupable)
Product (read-only)
Amount (fixed size and place)
City
ORD-10000
Hana Sato
France
Coffee
Filter beans
$75.60
Lyon
ORD-10001
Aiko Tan
Malaysia
Equipment
Kettle
$324.50
Penang
ORD-10002
Farah Aziz
Japan
Coffee
Espresso beans
$70.30
Osaka
ORD-10003
Farah Aziz
France
Equipment
Grinder
$774.00
Lyon
ORD-10004
Elif Kaya
Malaysia
Coffee
Espresso beans
$33.30
Kuala Lumpur
ORD-10005
Elif Kaya
Germany
Coffee
Filter beans
$154.00
Munich
ORD-10006
Ines Duarte
Germany
Tea
Oolong tea
$109.01
Munich
ORD-10007
Chen Wei
Japan
Equipment
Pour-over kit
$75.60
Osaka
ORD-10008
Farah Aziz
Germany
Coffee
Espresso beans
$94.35
Munich
ORD-10009
Farah Aziz
Japan
Equipment
Kettle
$606.82
Tokyo
ORD-10010
Dewi Lestari
Japan
Tea
Oolong tea
$102.00
Osaka
ORD-10011
Dewi Lestari
Malaysia
Equipment
Kettle
$493.24
Kuala Lumpur
ORD-10012
Farah Aziz
Japan
Equipment
Pour-over kit
$285.60
Osaka
ORD-10013
Chen Wei
France
Equipment
Kettle
$292.05
Reims
ORD-10014
Ines Duarte
France
Tea
Green tea
$55.50
Lyon
ORD-10015
Chen Wei
Germany
Equipment
Grinder
$767.55
Munich
ORD-10016
Goran Petrov
Germany
Coffee
Filter beans
$146.30
Munich
ORD-10017
Dewi Lestari
Japan
Coffee
Espresso beans
$210.90
Tokyo
ORD-10018
Farah Aziz
Germany
Coffee
Espresso beans
$123.03
Berlin
ORD-10019
Dewi Lestari
France
Equipment
Pour-over kit
$142.80
Reims
No events yet.

Row numbers

A column with type: 'rowNumber' and no field numbers the rows. The number is the position of the data row in the current view: it follows sorting and filtering, continues across pages (page 2 of 25-row pages starts at 26) and skips group captions and footers. Only rendered rows compute a number, so the column adds no work beyond the visible window. The column defaults to the header # (localeText.rowNumberColumnHeader), end alignment, and no sorting, filtering, searching, grouping or editing; its own fields win, and renderCell receives the number as value.

Row number column

Open demo

A type: 'rowNumber' column numbering 2,000 orders across pages, sorts and groups, with the header group toggle buttons.

Drag a column header here to group by that column
#
Order
Customer
Country
Category
Qty
Amount
1
ORD-10000
Hana Sato
Portugal
Equipment
5
$275.83
2
ORD-10001
Bao Nguyen
Japan
Equipment
9
$378.00
3
ORD-10002
Goran Petrov
Germany
Equipment
8
$285.60
4
ORD-10003
Farah Aziz
France
Coffee
1
$12.60
5
ORD-10004
Goran Petrov
France
Equipment
10
$649.00
6
ORD-10005
Bao Nguyen
Malaysia
Equipment
7
$279.30
7
ORD-10006
Bao Nguyen
France
Coffee
10
$133.00
8
ORD-10007
Elif Kaya
Malaysia
Equipment
11
$1,419.00
9
ORD-10008
Elif Kaya
France
Equipment
7
$903.00
10
ORD-10009
Bao Nguyen
Germany
Tea
7
$89.25
11
ORD-10010
Ines Duarte
Malaysia
Equipment
8
$519.20
12
ORD-10011
Chen Wei
Portugal
Coffee
4
$47.60
13
ORD-10012
Farah Aziz
Portugal
Coffee
3
$47.18
14
ORD-10013
Hana Sato
France
Coffee
1
$12.60
15
ORD-10014
Hana Sato
Portugal
Equipment
9
$1,044.90
16
ORD-10015
Aiko Tan
Portugal
Equipment
4
$151.20
17
ORD-10016
Dewi Lestari
Malaysia
Coffee
4
$50.40
18
ORD-10017
Hana Sato
Germany
Coffee
10
$133.00
19
ORD-10018
Bao Nguyen
France
Coffee
3
$39.90
20
ORD-10019
Farah Aziz
Portugal
Equipment
4
$438.60

Sort, page, or group with the header group buttons: the numbers count data rows in view order, continue across pages and skip group captions.

Visibility, resizing, reordering and auto-size

Columns are hidden and shown through the reactive column hidden field or by id or field through api.hideColumns() and api.showColumns(), which raise onBeforeColumnVisibilityChange (cancellable) and onColumnVisibilityChange. Resizing and reordering are opt in with the grid resizable and reorderable props. Header edges resize columns with the pointer and the keyboard; double-clicking an edge, or calling the auto-size method, fits the width to the header and the rendered cells. Headers drag to reorder, and Alt+ArrowLeft / Alt+ArrowRight move the focused header. Width, order and visibility are engine state, so they never re-render rows while a drag is in progress.

On a focused header, Ctrl+Alt+ArrowRight and Ctrl+Alt+ArrowLeft widen and narrow the column by 10 px (mirrored in RTL), and Ctrl+Alt+Enter auto-sizes it. Every width, from the pointer, the keyboard, auto-size, api.setColumnWidth() or a changed column.width, is clamped to the column's minWidth and maxWidth by the core.

Pointer resizes raise onColumnResizeStart, onColumnResize once per frame and onColumnResizeEnd with { field, width, previousWidth }; preventDefault() in onColumnResizeStart cancels the gesture. The keyboard resize keys raise the same three events once per key press with source: 'keyboard', so a reactive column.width stays in sync; api.autoSizeColumns() and the column menu auto-size items do not raise them. Header drags raise onColumnDragStart, onColumnDrag per frame and onColumnDrop with { field, fromIndex, toIndex } (toIndex is -1 while the drop target is invalid); every move, by pointer, keyboard or method, also raises onBeforeColumnReorder (cancellable) and onColumnReorder. preventDefault() in onBeforeColumnReorder keeps the column where it was: a pointer drag still reports onColumnDrop, but the order does not change and onColumnReorder does not fire. While a header is dragged, a preview with the header text follows the pointer and a line marks the drop position; both disappear on drop or when the pointer is cancelled (a cancelled pointer moves nothing).

api.moveColumn(field, toIndex) moves a column to an index of the visible columns; it is rejected across pinned zones and for locked columns. To keep widths, treat column.width as reactive state written back from onColumnResizeEnd, as the demo does for Customer, or let persistState save widths with the rest of the grid state (see State persistence).

Visibility, resize, reorder and auto-size

Open demo

Toggle columns through the reactive column hidden field or the API, drag header edges or press Ctrl+Alt+Arrow to resize within the min and max widths, drag headers or press Alt+Arrow to reorder (both opt in with resizable and reorderable), move columns with api.moveColumn, drive a width reactively, and watch the resize and drag events.

Visible columns
Order
Customer
City
Country
Product
Amount
ORD-10000
Dewi Lestari
Kuala Lumpur
Malaysia
Grinder
$986.85
ORD-10001
Bao Nguyen
Lyon
France
Oolong tea
$63.75
ORD-10002
Bao Nguyen
Reims
France
Filter beans
$53.20
ORD-10003
Aiko Tan
Osaka
Japan
Kettle
$431.59
ORD-10004
Chen Wei
Reims
France
Pour-over kit
$264.60
ORD-10005
Elif Kaya
Reims
France
Kettle
$551.65
ORD-10006
Bao Nguyen
Lyon
France
Grinder
$1,044.90
ORD-10007
Elif Kaya
Munich
Germany
Espresso beans
$185.00
ORD-10008
Bao Nguyen
Porto
Portugal
Green tea
$47.18
ORD-10009
Bao Nguyen
Reims
France
Green tea
$94.35
ORD-10010
Hana Sato
Munich
Germany
Oolong tea
$114.75
ORD-10011
Dewi Lestari
Munich
Germany
Green tea
$74.93
ORD-10012
Chen Wei
Porto
Portugal
Grinder
$857.85
ORD-10013
Bao Nguyen
Penang
Malaysia
Kettle
$55.17
ORD-10014
Hana Sato
Munich
Germany
Green tea
$99.90
ORD-10015
Farah Aziz
Osaka
Japan
Green tea
$8.79
ORD-10016
Aiko Tan
Kuala Lumpur
Malaysia
Filter beans
$159.60
ORD-10017
Farah Aziz
Lyon
France
Espresso beans
$149.85
ORD-10018
Chen Wei
Reims
France
Kettle
$61.66
ORD-10019
Goran Petrov
Reims
France
Oolong tea
$114.75
No events yet.

Column fit and computed headers

resizeMode picks how the columns relate to the grid width. 'normal', the default, keeps every width: narrow columns leave empty space at the end and wide ones scroll, and a resize changes only the resized column. With 'auto', columns narrower than the grid stretch in proportion to their width until they fill it, again whenever the grid is resized; maxWidth caps a column and columns with resizable: false (such as the selection column) keep their width. Dragging a header edge then re-fits the other columns live, and the release stores the fitted widths so nothing jumps. Columns are never shrunk below their widths to avoid scrolling: wide content still scrolls horizontally (shrinking below declared widths would truncate content and add a layout pass on every viewport resize). To fit more columns without scrolling, use resizeMode="auto" and give columns a smaller width or a percentage where they must fit without scrolling.

<DataGrid data={orders} columns={columns} resizable resizeMode="auto" />

headerValueGetter computes a header text from the compiled column, for example to add a unit or a currency. It runs when the column compiles, and its result is the header text everywhere: the header cell, the column chooser and menu, filter and group labels, accessible names, and CSV, Excel and PDF exports. Give it new values by passing a new column definition.

{ field: 'amount', type: 'number', headerValueGetter: () => `Amount (${currency})` }

Column fit and computed headers

Open demo

Switch resizeMode between 'auto' (columns stretch to fill the grid and a resize re-fits the others) and 'normal' (widths are kept and the space stays empty), and compute header text with headerValueGetter.

Order
Customer
Country
Qty (number)
Unit price (USD)
Amount (USD)
ORD-10000
Dewi Lestari
Malaysia
9
$129.00
$986.85
ORD-10001
Bao Nguyen
France
5
$12.75
$63.75
ORD-10002
Bao Nguyen
France
4
$14.00
$53.20
ORD-10003
Aiko Tan
Japan
7
$64.90
$431.59
ORD-10004
Chen Wei
France
7
$42.00
$264.60
ORD-10005
Elif Kaya
France
10
$64.90
$551.65
ORD-10006
Bao Nguyen
France
9
$129.00
$1,044.90
ORD-10007
Elif Kaya
Germany
10
$18.50
$185.00
ORD-10008
Bao Nguyen
Portugal
6
$9.25
$47.18
ORD-10009
Bao Nguyen
France
12
$9.25
$94.35
ORD-10010
Hana Sato
Germany
10
$12.75
$114.75
ORD-10011
Dewi Lestari
Germany
9
$9.25
$74.93
ORD-10012
Chen Wei
Portugal
7
$129.00
$857.85
ORD-10013
Bao Nguyen
Malaysia
1
$64.90
$55.17
ORD-10014
Hana Sato
Germany
12
$9.25
$99.90
ORD-10015
Farah Aziz
Japan
1
$9.25
$8.79
ORD-10016
Aiko Tan
Malaysia
12
$14.00
$159.60
ORD-10017
Farah Aziz
France
9
$18.50
$149.85
ORD-10018
Chen Wei
France
1
$64.90
$61.66
ORD-10019
Goran Petrov
France
9
$12.75
$114.75
No events yet.

API reference

DataGridColumn and the core ColumnDef list every column field; the column methods are on DataGridApi.