Data table
A data table shows read-only rows and columns, so readers can compare values and screen readers can browse them. Choose whether a phone sees a table that scrolls sideways or rows restacked as labeled blocks; sorting needs no wiring beyond marking a column sortable. The tables below show both variants at different densities.
| Seed | Mood |
|---|---|
| Cobalt | Calm |
| Vermilion | Bold |
| Dish | Price | Heat |
|---|---|---|
| Laksa | $11 | Hot |
| Soba | $9 | Mild |
| Team | Points |
|---|---|
| Otters | 42 |
| Herons | 37 |
| Task | Owner |
|---|---|
| Login | Ada |
| Docs | Grace |
| Drink | Price |
|---|---|
| Latte | $4 |
| Cortado | $4 |
| Mocha | $6 |
| Track | Time |
|---|---|
| Kite | 3:12 |
| Track | Time |
|---|---|
| Lantern | 2:48 |
Reference docs
Choosing a way to show a collection
Three components show many items at once. Each suits a different job:
- List: a column of items to scan and act on, such as contacts or settings.
- Data table: read-only rows and columns to compare, such as an invoice or a price table.
- Data grid: many rows the reader sorts, selects, and moves through by keyboard, such as an order list of thousands.
One job belongs elsewhere. Splitting a long collection into pages is a paginator, used alongside any of these.
Choosing a variant
Two variants set how much a data table stands out from the page, from most to least:
- Surface: a table that needs its own ground, such as a list in a panel of another color, on the lowest surface container color.
- Standard: the default, with no fill, for a table that sits directly on the page or inside a card, such as an invoice list, and takes that container's color.
Built in
- A column marked
sortablein sorts when its header is activated, and a screen reader announces the new order.columns restacks each row as a block with every value beside its column title, so a narrow screen needs no sideways scrolling.stack- A long cell wraps, so every word stays readable: the row grows rather than cutting the text.
cuts it off with an ellipsis instead, and the full text appears when a pointer rests on the cell.truncate-cells keeps a table of thousands of rows light.virtualize- Markup you already have works: a table written inside the element becomes a data table.
puts your own content in a cell, such as a link or a status label, through a child with atemplateFieldscell:slot name.
Using data tables well
- Give a numeric column the
numberorcurrencytype, so its values sit at the end of the cell, and leave text columns at the start. - Give a
currencycolumn its currency code, such as"currency": "EUR". The table's language, thelangit inherits, decides how a price is written, not which currency it is in, and a column with no code shows plain numbers. - Keep column titles short, and move any explanation to the caption.
- Put paging controls in a footer below the table, with a rows-per-page choice and a position readout such as 1–10 of 100, and slice the data yourself when the page changes.
- Choose a data grid when rows need selecting, since a data table has no selection and no checkbox column.
- Set
tostack for a table people open on a phone, and leave it at the default for a table whose columns must stay aligned.auto
These rules follow Material 3 Expressive's guidance for data tables, on material.io.
Variants
variantstandard
Caption position
The default slot holds the caption, which also serves as the table's name. caption-positionleadinggrid-label
Density
density0 (the roomiest) to 4 (the tightest), five values in all. Omit it and the table takes the density from your style configuration, which is standard
Stack
stackneveralwaysauto
Columns and rows
itemscolumnscolumnssortable and its header becomes a button; activating it cycles through ascending, descending, and unsorted. Sorting is set per column: the table itself has no sortable attribute. Set unique-identifier
Each framework writes a column in its own way:
- Web: an object, such as
{ field: "amount", title: "Amount", type: "currency", currency: "USD", sortable: true }. - React: the same object, in an array declared as
ColumnDefinition[], a type you import from@materia-technologies-inc/chameleon-components-react. Without that type, TypeScript widens"currency"tostringand rejects the array. Declare the row type withtype, notinterface, because a row must fitGridItem, and an interface does not. - Blazor:
ColumnDefinitionis a record, and its constructor takes the field. Writenew("Amount") { Title = "Amount", Type = TableColumnKind.Currency, Currency = "USD", Sortable = true }. The formnew() { Field = "Amount" }does not compile, andTypetakes aTableColumnKindmember, not text.
In Blazor, rows reach the browser under their C# property names, exactly as written. A row type record Invoice(string Id, string Customer, decimal Amount) takes new("Customer") and UniqueIdentifier="Id"; a lowercase "id" matches nothing. Razor works out TItem from Items="@invoices". Write it yourself, such as <CbDataTable TItem="Invoice" ...>, when the table has no Items.
Each sort fires sort-change. Its detail carries column, the sorted column's field, and direction, which is "asc", "desc" or "none". In Blazor, the OnSortChange handler takes SortChangeEventArgs and reads args.Column and args.Direction, a SortChangeDirection member such as SortChangeDirection.Asc. Blazor event arguments carry these fields directly and have no Detail.
Lines and stripes
stripedshow-column-dividersborderless
Wrapping text
By default a cell wraps text that does not fit: rows grow to fit, and the table scrolls sideways when its content is wider than its space. truncate-cells
Cell content
templateFieldsslot="cell:{rowKey}:{field}" for each cell, where rowKey is the row's value in the unique-identifier
Large data sets
virtualizeheight to scroll within. overscan-countitemsProvidervirtualize
The provider receives a request with the first row's index and a row count, and returns those rows with the total count. In Blazor it is a method such as Task<GridItemsProviderResult<Shipment>> LoadAsync(GridRequest request) that returns new GridItemsProviderResult<Shipment>(rows, total). Razor cannot work out TItem from a method, so write it: <CbDataTable TItem="Shipment" ItemsProvider="@LoadAsync" ...>.
Written table
A <table> written inside the element is its source, so crawlers and readers without script still see the rows. Header cells take options such as data-cw-field and data-cw-sortable. In Blazor, a table with written rows has no Items to infer from, so write TItem="object" on it.
Properties
| Property | Attribute | Type | Description |
|---|---|---|---|
borderless | borderless | booleandefault false | Removes the table's outer frame. The header's underline stays, drawn in the row divider's color and width, as do the row and cell dividers. See Lines and stripes. |
captionPosition | caption-positionleading, trailing | CaptionPositionCaptionPosition.Leading, .Trailingdefault CaptionPosition.Leading, from the style configuration | The caption's position in relation to the component. See Caption position. |
columns | ColumnDefinition[]default [] | Column definitions. If not provided, columns will be auto-generated from data (if possible). See Columns and rows. | |
density | density0, 1, 2, 3, 4 | DensityDensity.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | How tightly rows are spaced, from 0, the roomiest, to 4, the tightest. See Density. |
gridLabel | grid-label | string | The name a screen reader announces for the component. See Caption position. |
items | TItem[]default [] | Data source as an array of objects. Use this for client-side data. See Columns and rows. | |
itemsProvider | GridItemsProvider<TItem> | Async function to provide data. Use this for server-side operations (filtering, sorting, paging). Ignored while items has rows. See Large data sets. | |
overscanCount | overscan-count | numberdefault 3 | How many rows beyond the visible ones are fetched ahead of scrolling. Keep it small to avoid over-fetching from the server. See Large data sets. |
showColumnDividers | show-column-dividers | booleandefault false | Shows vertical dividers between columns, which helps tell columns apart when there are many. See Lines and stripes. |
stack | stacknever, always, auto | TableStackTableStack.Never, .Always, .Autodefault TableStack.Never | How the table fits a narrow width. always draws each row as a block, with every value beside its column's title; auto does so only while the table is too narrow, measured with its rows as rows: the width it has is less than the table needs with every column as narrow as it can be. That is a width test, not an overflow test. Text that wraps does not stack the table; a table stacks when the space is narrower than its columns' longest unbreakable words and their padding, a phone-width table in practice.Has no effect while virtualize is set: a virtualized table draws its rows as rows. See Stack. |
striped | striped | booleandefault false | Shades alternate rows. See Lines and stripes. |
templateFields | string[]default [] | The fields whose cells show content the page supplies, through a child with slot="cell:{rowKey}:{field}", rather than their value. Every cell of such a field shows its slot, so the content can arrive after the row is drawn; rows-change names the rows drawn. {rowKey} is the row's value in the uniqueIdentifier field, which these fields need.A written <table> needs no list: any written cell with such a child shows it in place of its copy. See Cell content. | |
touchTarget | touch-targetnone, overflow, wrapper | TouchTargetTouchTarget.None, .Overflow, .Wrapperdefault TouchTarget.Overflow, from the style configuration | The touch target of the sort buttons in the header: none leaves the buttons their visible area, and overflow adds a touch target as large as the header cell and never past it, so a header shorter than 48 pixels gives no press to the first row. wrapper is read as overflow: a sort button fills its header cell, so an added wrapper would only make the header taller, and the table never does that. The configuration supplies the default. |
truncateCells | truncate-cells | booleandefault false | Cells cut their text off with an ellipsis rather than wrapping it, and show the full text as the cell's hover title. By default cells wrap: rows grow to fit, the row height is a minimum, columns size to their content and the table scrolls sideways when its content is wider than its space. A cut-off cell's text can be reached by pointer alone, so set this where rows must keep one height and the text is not needed to read the table.A virtualized table wraps as well, and its rows grow to fit; its columns keep their widths, so the header stays over its column. See Wrapping text. |
uniqueIdentifier | unique-identifier | string | The name of a field whose value identifies a row. Optional, except when templateFields is set. Without it, the table cannot restore keyboard focus to the same row after a sort, filter or page change, so it drops focus. See Columns and rows, Cell content. |
variant | variantstandard, surface | TableVariantTableVariant.Standard, .Surfacedefault TableVariant.Standard, from the style configuration | The component's color scheme. surface uses the lowest surface container color, and standard no fill, taking the color of whatever the table sits on. Unset, it comes from the style configuration's defaultTableVariant, which ships as standard. See Variants. |
virtualize | virtualize | booleandefault false | Shows only the rows in view, for large datasets. Rows may differ in height: each is measured as it is drawn. See Large data sets. |
When itemsitemsProvideritemsitemsvirtualize
Slots
| Slot | Description |
|---|---|
| (default) | Caption content displayed above or below the table. Not rendered while a written <table> is the source; its <caption> is shown instead. |
A child with slot name cell:{rowKey}:{field} fills one cell; see templateFieldsgrid-label
Events
| Event | Type | Detail | Description |
|---|---|---|---|
sort-change | SortChangeEvent | SortChangeEventDetail | Dispatched when the sort state changes (a sortable column header is activated). It bubbles and is composed. |
rows-change | RowsChangeEvent | RowsChangeEventDetail | Dispatched when the rows drawn change, naming each drawn row's key in order, so a page can supply cell-slot content for the drawn rows alone. It bubbles and is composed. |
cell-activate | CellActivateEvent | CellActivateEventDetail<TItem> | Dispatched when a control rendered by ColumnDefinition.actionLabel/actionHref is activated: by pointer or Enter, and by Space on an actionLabel button. It bubbles and is composed. |
With itemsitemsProvidersortDescriptors, and the provider must sort.
Props
| Prop | Type | Description |
|---|---|---|
borderless | booleandefault false | Removes the table's outer frame. The header's underline stays, drawn in the row divider's color and width, as do the row and cell dividers. See Lines and stripes. |
captionPosition | CaptionPositionTypeCaptionPosition.Leading, .Trailingdefault CaptionPosition.Leading, from the style configuration | The caption's position in relation to the component. See Caption position. |
columns | ColumnDefinition[]default [] | Column definitions. If not provided, columns will be auto-generated from data (if possible). See Columns and rows. |
density | DensityTypeDensity.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | How tightly rows are spaced, from 0, the roomiest, to 4, the tightest. See Density. |
gridLabel | string | The name a screen reader announces for the component. See Caption position. |
items | TItem[]default [] | Data source as an array of objects. Use this for client-side data. See Columns and rows. |
itemsProvider | GridItemsProvider<TItem> | Async function to provide data. Use this for server-side operations (filtering, sorting, paging). Ignored while items has rows. See Large data sets. |
overscanCount | numberdefault 3 | How many rows beyond the visible ones are fetched ahead of scrolling. Keep it small to avoid over-fetching from the server. See Large data sets. |
showColumnDividers | booleandefault false | Shows vertical dividers between columns, which helps tell columns apart when there are many. See Lines and stripes. |
stack | TableStackTypeTableStack.Never, .Always, .Autodefault TableStack.Never | How the table fits a narrow width. always draws each row as a block, with every value beside its column's title; auto does so only while the table is too narrow, measured with its rows as rows: the width it has is less than the table needs with every column as narrow as it can be. That is a width test, not an overflow test. Text that wraps does not stack the table; a table stacks when the space is narrower than its columns' longest unbreakable words and their padding, a phone-width table in practice.Has no effect while virtualize is set: a virtualized table draws its rows as rows. See Stack. |
striped | booleandefault false | Shades alternate rows. See Lines and stripes. |
templateFields | string[]default [] | The fields whose cells show content the page supplies, through a child with slot="cell:{rowKey}:{field}", rather than their value. Every cell of such a field shows its slot, so the content can arrive after the row is drawn; rows-change names the rows drawn. {rowKey} is the row's value in the uniqueIdentifier field, which these fields need.A written <table> needs no list: any written cell with such a child shows it in place of its copy. See Cell content. |
touchTarget | TouchTargetTypeTouchTarget.None, .Overflow, .Wrapperdefault TouchTarget.Overflow, from the style configuration | The touch target of the sort buttons in the header: none leaves the buttons their visible area, and overflow adds a touch target as large as the header cell and never past it, so a header shorter than 48 pixels gives no press to the first row. wrapper is read as overflow: a sort button fills its header cell, so an added wrapper would only make the header taller, and the table never does that. The configuration supplies the default. |
truncateCells | booleandefault false | Cells cut their text off with an ellipsis rather than wrapping it, and show the full text as the cell's hover title. By default cells wrap: rows grow to fit, the row height is a minimum, columns size to their content and the table scrolls sideways when its content is wider than its space. A cut-off cell's text can be reached by pointer alone, so set this where rows must keep one height and the text is not needed to read the table.A virtualized table wraps as well, and its rows grow to fit; its columns keep their widths, so the header stays over its column. See Wrapping text. |
uniqueIdentifier | string | The name of a field whose value identifies a row. Optional, except when templateFields is set. Without it, the table cannot restore keyboard focus to the same row after a sort, filter or page change, so it drops focus. See Columns and rows, Cell content. |
variant | TableVariantTypeTableVariant.Standard, .Surfacedefault TableVariant.Standard, from the style configuration | The component's color scheme. surface uses the lowest surface container color, and standard no fill, taking the color of whatever the table sits on. Unset, it comes from the style configuration's defaultTableVariant, which ships as standard. See Variants. |
virtualize | booleandefault false | Shows only the rows in view, for large datasets. Rows may differ in height: each is measured as it is drawn. See Large data sets. |
When itemsitemsProvideritemsitemsvirtualize
Children
| Child | Description |
|---|---|
children | Caption content displayed above or below the table. Not rendered while a written <table> is the source; its <caption> is shown instead. |
A child with slot name cell:{rowKey}:{field} fills one cell; see templateFieldsgrid-label
Events
| Prop | Argument | Description |
|---|---|---|
onSortChange | SortChangeEvent | Dispatched when the sort state changes (a sortable column header is activated). It bubbles and is composed. Its detail carries column, direction, and sortDescriptors. |
onRowsChange | RowsChangeEvent | Dispatched when the rows drawn change, naming each drawn row's key in order, so a page can supply cell-slot content for the drawn rows alone. It bubbles and is composed. Its detail carries keys. |
onCellActivate | CellActivateEvent<TItem> | Dispatched when a control rendered by ColumnDefinition.actionLabel/actionHref is activated: by pointer or Enter, and by Space on an actionLabel button. It bubbles and is composed. Its detail carries item, rowIndex, field, columnIndex, value, and originalEvent. |
With itemsitemsProvidersortDescriptors, and the provider must sort.
Parameters
| Parameter | Type | Description |
|---|---|---|
Borderless | bool?default false | Removes the table's outer frame. The header's underline stays, drawn in the row divider's color and width, as do the row and cell dividers. See Lines and stripes. |
CaptionPosition | CaptionPosition?CaptionPosition.Leading, .Trailingdefault CaptionPosition.Leading, from the style configuration | The caption's position in relation to the component. See Caption position. |
Columnsinteractive rendering only | IEnumerable<ColumnDefinition>?default [] | Column definitions. If not provided, columns will be auto-generated from data (if possible). See Columns and rows. |
Density | Density?Density.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | How tightly rows are spaced, from 0, the roomiest, to 4, the tightest. See Density. |
GridLabel | string? | The name a screen reader announces for the component. See Caption position. |
Itemsinteractive rendering only | IEnumerable<TItem>?default [] | Data source as an array of objects. Use this for client-side data. See Columns and rows. |
ItemsProviderinteractive rendering only | GridItemsProvider<TItem>? | Async function to provide data. Use this for server-side operations (filtering, sorting, paging). Ignored while Items has rows. See Large data sets. |
OverscanCount | int?default 3 | How many rows beyond the visible ones are fetched ahead of scrolling. Keep it small to avoid over-fetching from the server. See Large data sets. |
ShowColumnDividers | bool?default false | Shows vertical dividers between columns, which helps tell columns apart when there are many. See Lines and stripes. |
Stack | TableStack?TableStack.Never, .Always, .Autodefault TableStack.Never | How the table fits a narrow width. always draws each row as a block, with every value beside its column's title; auto does so only while the table is too narrow, measured with its rows as rows: the width it has is less than the table needs with every column as narrow as it can be. That is a width test, not an overflow test. Text that wraps does not stack the table; a table stacks when the space is narrower than its columns' longest unbreakable words and their padding, a phone-width table in practice.Has no effect while Virtualize is set: a virtualized table draws its rows as rows. See Stack. |
Striped | bool?default false | Shades alternate rows. See Lines and stripes. |
TemplateFieldsinteractive rendering only | IEnumerable<string>?default [] | The fields whose cells show content the page supplies, through a child with slot="cell:{rowKey}:{field}", rather than their value. Every cell of such a field shows its slot, so the content can arrive after the row is drawn; rows-change names the rows drawn. {rowKey} is the row's value in the UniqueIdentifier field, which these fields need.A written <table> needs no list: any written cell with such a child shows it in place of its copy. See Cell content. |
TouchTarget | TouchTarget?TouchTarget.None, .Overflow, .Wrapperdefault TouchTarget.Overflow, from the style configuration | The touch target of the sort buttons in the header: none leaves the buttons their visible area, and overflow adds a touch target as large as the header cell and never past it, so a header shorter than 48 pixels gives no press to the first row. wrapper is read as overflow: a sort button fills its header cell, so an added wrapper would only make the header taller, and the table never does that. The configuration supplies the default. |
TruncateCells | bool?default false | Cells cut their text off with an ellipsis rather than wrapping it, and show the full text as the cell's hover title. By default cells wrap: rows grow to fit, the row height is a minimum, columns size to their content and the table scrolls sideways when its content is wider than its space. A cut-off cell's text can be reached by pointer alone, so set this where rows must keep one height and the text is not needed to read the table.A virtualized table wraps as well, and its rows grow to fit; its columns keep their widths, so the header stays over its column. See Wrapping text. |
UniqueIdentifier | string? | The name of a field whose value identifies a row. Optional, except when TemplateFields is set. Without it, the table cannot restore keyboard focus to the same row after a sort, filter or page change, so it drops focus. See Columns and rows, Cell content. |
Variant | TableVariant?TableVariant.Standard, .Surfacedefault TableVariant.Standard, from the style configuration | The component's color scheme. surface uses the lowest surface container color, and standard no fill, taking the color of whatever the table sits on. Unset, it comes from the style configuration's defaultTableVariant, which ships as standard. See Variants. |
Virtualize | bool?default false | Shows only the rows in view, for large datasets. Rows may differ in height: each is measured as it is drawn. See Large data sets. |
When itemsitemsProvideritemsitemsvirtualize
Render fragments
| Parameter | Type | Description |
|---|---|---|
ChildContent | RenderFragment? | Caption content displayed above or below the table. Not rendered while a written <table> is the source; its <caption> is shown instead. |
A child with slot name cell:{rowKey}:{field} fills one cell; see templateFieldsgrid-label
Event callbacks
| Parameter | Type | Description |
|---|---|---|
OnSortChange | EventCallback<SortChangeEventArgs> | Dispatched when the sort state changes (a sortable column header is activated). It bubbles and is composed. The handler's argument has Column, Direction, and SortDescriptors: read args.Column; there is no Detail. |
OnRowsChange | EventCallback<RowsChangeEventArgs> | Dispatched when the rows drawn change, naming each drawn row's key in order, so a page can supply cell-slot content for the drawn rows alone. It bubbles and is composed. The handler's argument has Keys: read args.Keys; there is no Detail. |
OnCellActivate | EventCallback<CellActivateEventArgs<TItem>> | Dispatched when a control rendered by ColumnDefinition.actionLabel/actionHref is activated: by pointer or Enter, and by Space on an actionLabel button. It bubbles and is composed. The handler's argument has Item, RowIndex, Field, ColumnIndex, Value, and OriginalEvent: read args.Item; there is no Detail. |
With itemsitemsProvidersortDescriptors, and the provider must sort.
Inputs
| Input | Type | Description |
|---|---|---|
borderless | booleandefault false | Removes the table's outer frame. The header's underline stays, drawn in the row divider's color and width, as do the row and cell dividers. See Lines and stripes. |
captionPosition | CaptionPositionTypeCaptionPosition.Leading, .Trailingdefault CaptionPosition.Leading, from the style configuration | The caption's position in relation to the component. See Caption position. |
columns | ColumnDefinition[]default [] | Column definitions. If not provided, columns will be auto-generated from data (if possible). See Columns and rows. |
density | DensityTypeDensity.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | How tightly rows are spaced, from 0, the roomiest, to 4, the tightest. See Density. |
gridLabel | string | The name a screen reader announces for the component. See Caption position. |
items | TItem[]default [] | Data source as an array of objects. Use this for client-side data. See Columns and rows. |
itemsProvider | GridItemsProvider<TItem> | Async function to provide data. Use this for server-side operations (filtering, sorting, paging). Ignored while items has rows. See Large data sets. |
overscanCount | numberdefault 3 | How many rows beyond the visible ones are fetched ahead of scrolling. Keep it small to avoid over-fetching from the server. See Large data sets. |
showColumnDividers | booleandefault false | Shows vertical dividers between columns, which helps tell columns apart when there are many. See Lines and stripes. |
stack | TableStackTypeTableStack.Never, .Always, .Autodefault TableStack.Never | How the table fits a narrow width. always draws each row as a block, with every value beside its column's title; auto does so only while the table is too narrow, measured with its rows as rows: the width it has is less than the table needs with every column as narrow as it can be. That is a width test, not an overflow test. Text that wraps does not stack the table; a table stacks when the space is narrower than its columns' longest unbreakable words and their padding, a phone-width table in practice.Has no effect while virtualize is set: a virtualized table draws its rows as rows. See Stack. |
striped | booleandefault false | Shades alternate rows. See Lines and stripes. |
templateFields | string[]default [] | The fields whose cells show content the page supplies, through a child with slot="cell:{rowKey}:{field}", rather than their value. Every cell of such a field shows its slot, so the content can arrive after the row is drawn; rows-change names the rows drawn. {rowKey} is the row's value in the uniqueIdentifier field, which these fields need.A written <table> needs no list: any written cell with such a child shows it in place of its copy. See Cell content. |
touchTarget | TouchTargetTypeTouchTarget.None, .Overflow, .Wrapperdefault TouchTarget.Overflow, from the style configuration | The touch target of the sort buttons in the header: none leaves the buttons their visible area, and overflow adds a touch target as large as the header cell and never past it, so a header shorter than 48 pixels gives no press to the first row. wrapper is read as overflow: a sort button fills its header cell, so an added wrapper would only make the header taller, and the table never does that. The configuration supplies the default. |
truncateCells | booleandefault false | Cells cut their text off with an ellipsis rather than wrapping it, and show the full text as the cell's hover title. By default cells wrap: rows grow to fit, the row height is a minimum, columns size to their content and the table scrolls sideways when its content is wider than its space. A cut-off cell's text can be reached by pointer alone, so set this where rows must keep one height and the text is not needed to read the table.A virtualized table wraps as well, and its rows grow to fit; its columns keep their widths, so the header stays over its column. See Wrapping text. |
uniqueIdentifier | string | The name of a field whose value identifies a row. Optional, except when templateFields is set. Without it, the table cannot restore keyboard focus to the same row after a sort, filter or page change, so it drops focus. See Columns and rows, Cell content. |
variant | TableVariantTypeTableVariant.Standard, .Surfacedefault TableVariant.Standard, from the style configuration | The component's color scheme. surface uses the lowest surface container color, and standard no fill, taking the color of whatever the table sits on. Unset, it comes from the style configuration's defaultTableVariant, which ships as standard. See Variants. |
virtualize | booleandefault false | Shows only the rows in view, for large datasets. Rows may differ in height: each is measured as it is drawn. See Large data sets. |
When itemsitemsProvideritemsitemsvirtualize
Content projection
| Content | Description |
|---|---|
content with no slot | Caption content displayed above or below the table. Not rendered while a written <table> is the source; its <caption> is shown instead. |
A child with slot name cell:{rowKey}:{field} fills one cell; see templateFieldsgrid-label
Outputs
| Output | Event | Description |
|---|---|---|
cwSortChange | SortChangeEvent | Dispatched when the sort state changes (a sortable column header is activated). It bubbles and is composed. Its detail carries column, direction, and sortDescriptors. |
cwRowsChange | RowsChangeEvent | Dispatched when the rows drawn change, naming each drawn row's key in order, so a page can supply cell-slot content for the drawn rows alone. It bubbles and is composed. Its detail carries keys. |
cwCellActivate | CellActivateEvent | Dispatched when a control rendered by ColumnDefinition.actionLabel/actionHref is activated: by pointer or Enter, and by Space on an actionLabel button. It bubbles and is composed. Its detail carries item, rowIndex, field, columnIndex, value, and originalEvent. |
With itemsitemsProvidersortDescriptors, and the provider must sort.
Props
| Prop | Type | Description |
|---|---|---|
borderless | booleandefault false | Removes the table's outer frame. The header's underline stays, drawn in the row divider's color and width, as do the row and cell dividers. See Lines and stripes. |
captionPosition | CaptionPositionTypeCaptionPosition.Leading, .Trailingdefault CaptionPosition.Leading, from the style configuration | The caption's position in relation to the component. See Caption position. |
columns | ColumnDefinition[]default [] | Column definitions. If not provided, columns will be auto-generated from data (if possible). See Columns and rows. |
density | DensityTypeDensity.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | How tightly rows are spaced, from 0, the roomiest, to 4, the tightest. See Density. |
gridLabel | string | The name a screen reader announces for the component. See Caption position. |
items | TItem[]default [] | Data source as an array of objects. Use this for client-side data. See Columns and rows. |
itemsProvider | GridItemsProvider<TItem> | Async function to provide data. Use this for server-side operations (filtering, sorting, paging). Ignored while items has rows. See Large data sets. |
overscanCount | numberdefault 3 | How many rows beyond the visible ones are fetched ahead of scrolling. Keep it small to avoid over-fetching from the server. See Large data sets. |
showColumnDividers | booleandefault false | Shows vertical dividers between columns, which helps tell columns apart when there are many. See Lines and stripes. |
stack | TableStackTypeTableStack.Never, .Always, .Autodefault TableStack.Never | How the table fits a narrow width. always draws each row as a block, with every value beside its column's title; auto does so only while the table is too narrow, measured with its rows as rows: the width it has is less than the table needs with every column as narrow as it can be. That is a width test, not an overflow test. Text that wraps does not stack the table; a table stacks when the space is narrower than its columns' longest unbreakable words and their padding, a phone-width table in practice.Has no effect while virtualize is set: a virtualized table draws its rows as rows. See Stack. |
striped | booleandefault false | Shades alternate rows. See Lines and stripes. |
templateFields | string[]default [] | The fields whose cells show content the page supplies, through a child with slot="cell:{rowKey}:{field}", rather than their value. Every cell of such a field shows its slot, so the content can arrive after the row is drawn; rows-change names the rows drawn. {rowKey} is the row's value in the uniqueIdentifier field, which these fields need.A written <table> needs no list: any written cell with such a child shows it in place of its copy. See Cell content. |
touchTarget | TouchTargetTypeTouchTarget.None, .Overflow, .Wrapperdefault TouchTarget.Overflow, from the style configuration | The touch target of the sort buttons in the header: none leaves the buttons their visible area, and overflow adds a touch target as large as the header cell and never past it, so a header shorter than 48 pixels gives no press to the first row. wrapper is read as overflow: a sort button fills its header cell, so an added wrapper would only make the header taller, and the table never does that. The configuration supplies the default. |
truncateCells | booleandefault false | Cells cut their text off with an ellipsis rather than wrapping it, and show the full text as the cell's hover title. By default cells wrap: rows grow to fit, the row height is a minimum, columns size to their content and the table scrolls sideways when its content is wider than its space. A cut-off cell's text can be reached by pointer alone, so set this where rows must keep one height and the text is not needed to read the table.A virtualized table wraps as well, and its rows grow to fit; its columns keep their widths, so the header stays over its column. See Wrapping text. |
uniqueIdentifier | string | The name of a field whose value identifies a row. Optional, except when templateFields is set. Without it, the table cannot restore keyboard focus to the same row after a sort, filter or page change, so it drops focus. See Columns and rows, Cell content. |
variant | TableVariantTypeTableVariant.Standard, .Surfacedefault TableVariant.Standard, from the style configuration | The component's color scheme. surface uses the lowest surface container color, and standard no fill, taking the color of whatever the table sits on. Unset, it comes from the style configuration's defaultTableVariant, which ships as standard. See Variants. |
virtualize | booleandefault false | Shows only the rows in view, for large datasets. Rows may differ in height: each is measured as it is drawn. See Large data sets. |
When itemsitemsProvideritemsitemsvirtualize
Slots
| Slot | Description |
|---|---|
default | Caption content displayed above or below the table. Not rendered while a written <table> is the source; its <caption> is shown instead. |
A child with slot name cell:{rowKey}:{field} fills one cell; see templateFieldsgrid-label
Events
| Event | Type | Description |
|---|---|---|
sortChange | SortChangeEvent | Dispatched when the sort state changes (a sortable column header is activated). It bubbles and is composed. Its detail carries column, direction, and sortDescriptors. |
rowsChange | RowsChangeEvent | Dispatched when the rows drawn change, naming each drawn row's key in order, so a page can supply cell-slot content for the drawn rows alone. It bubbles and is composed. Its detail carries keys. |
cellActivate | CellActivateEvent | Dispatched when a control rendered by ColumnDefinition.actionLabel/actionHref is activated: by pointer or Enter, and by Space on an actionLabel button. It bubbles and is composed. Its detail carries item, rowIndex, field, columnIndex, value, and originalEvent. |
With itemsitemsProvidersortDescriptors, and the provider must sort.
Props
| Prop | Type | Description |
|---|---|---|
borderless | booleandefault false | Removes the table's outer frame. The header's underline stays, drawn in the row divider's color and width, as do the row and cell dividers. See Lines and stripes. |
captionPosition | CaptionPositionTypeCaptionPosition.Leading, .Trailingdefault CaptionPosition.Leading, from the style configuration | The caption's position in relation to the component. See Caption position. |
columns | ColumnDefinition[]default [] | Column definitions. If not provided, columns will be auto-generated from data (if possible). See Columns and rows. |
density | DensityTypeDensity.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | How tightly rows are spaced, from 0, the roomiest, to 4, the tightest. See Density. |
gridLabel | string | The name a screen reader announces for the component. See Caption position. |
items | TItem[]default [] | Data source as an array of objects. Use this for client-side data. See Columns and rows. |
itemsProvider | GridItemsProvider<TItem> | Async function to provide data. Use this for server-side operations (filtering, sorting, paging). Ignored while items has rows. See Large data sets. |
overscanCount | numberdefault 3 | How many rows beyond the visible ones are fetched ahead of scrolling. Keep it small to avoid over-fetching from the server. See Large data sets. |
showColumnDividers | booleandefault false | Shows vertical dividers between columns, which helps tell columns apart when there are many. See Lines and stripes. |
stack | TableStackTypeTableStack.Never, .Always, .Autodefault TableStack.Never | How the table fits a narrow width. always draws each row as a block, with every value beside its column's title; auto does so only while the table is too narrow, measured with its rows as rows: the width it has is less than the table needs with every column as narrow as it can be. That is a width test, not an overflow test. Text that wraps does not stack the table; a table stacks when the space is narrower than its columns' longest unbreakable words and their padding, a phone-width table in practice.Has no effect while virtualize is set: a virtualized table draws its rows as rows. See Stack. |
striped | booleandefault false | Shades alternate rows. See Lines and stripes. |
templateFields | string[]default [] | The fields whose cells show content the page supplies, through a child with slot="cell:{rowKey}:{field}", rather than their value. Every cell of such a field shows its slot, so the content can arrive after the row is drawn; rows-change names the rows drawn. {rowKey} is the row's value in the uniqueIdentifier field, which these fields need.A written <table> needs no list: any written cell with such a child shows it in place of its copy. See Cell content. |
touchTarget | TouchTargetTypeTouchTarget.None, .Overflow, .Wrapperdefault TouchTarget.Overflow, from the style configuration | The touch target of the sort buttons in the header: none leaves the buttons their visible area, and overflow adds a touch target as large as the header cell and never past it, so a header shorter than 48 pixels gives no press to the first row. wrapper is read as overflow: a sort button fills its header cell, so an added wrapper would only make the header taller, and the table never does that. The configuration supplies the default. |
truncateCells | booleandefault false | Cells cut their text off with an ellipsis rather than wrapping it, and show the full text as the cell's hover title. By default cells wrap: rows grow to fit, the row height is a minimum, columns size to their content and the table scrolls sideways when its content is wider than its space. A cut-off cell's text can be reached by pointer alone, so set this where rows must keep one height and the text is not needed to read the table.A virtualized table wraps as well, and its rows grow to fit; its columns keep their widths, so the header stays over its column. See Wrapping text. |
uniqueIdentifier | string | The name of a field whose value identifies a row. Optional, except when templateFields is set. Without it, the table cannot restore keyboard focus to the same row after a sort, filter or page change, so it drops focus. See Columns and rows, Cell content. |
variant | TableVariantTypeTableVariant.Standard, .Surfacedefault TableVariant.Standard, from the style configuration | The component's color scheme. surface uses the lowest surface container color, and standard no fill, taking the color of whatever the table sits on. Unset, it comes from the style configuration's defaultTableVariant, which ships as standard. See Variants. |
virtualize | booleandefault false | Shows only the rows in view, for large datasets. Rows may differ in height: each is measured as it is drawn. See Large data sets. |
When itemsitemsProvideritemsitemsvirtualize
Snippets
| Snippet | Description |
|---|---|
children | Caption content displayed above or below the table. Not rendered while a written <table> is the source; its <caption> is shown instead. |
A child with slot name cell:{rowKey}:{field} fills one cell; see templateFieldsgrid-label
Events
| Prop | Type | Description |
|---|---|---|
onSortChange | SortChangeEvent | Dispatched when the sort state changes (a sortable column header is activated). It bubbles and is composed. Its detail carries column, direction, and sortDescriptors. |
onRowsChange | RowsChangeEvent | Dispatched when the rows drawn change, naming each drawn row's key in order, so a page can supply cell-slot content for the drawn rows alone. It bubbles and is composed. Its detail carries keys. |
onCellActivate | CellActivateEvent | Dispatched when a control rendered by ColumnDefinition.actionLabel/actionHref is activated: by pointer or Enter, and by Space on an actionLabel button. It bubbles and is composed. Its detail carries item, rowIndex, field, columnIndex, value, and originalEvent. |
With itemsitemsProvidersortDescriptors, and the provider must sort.
Each attribute value has its own tokens; a cell shows its token's value, and selecting the cell shows the token's fallback path, with each name and value ready to copy. For example, the standard column's error-color row is --ct-table-standard-error-color, which defaults to --ct-sys-color-error.
Variant
| Name | standard | surface |
|---|---|---|
error-color | --ct-sys-color-error --ct-table-standard-error-color | --ct-sys-color-error --ct-table-surface-error-color |
error-container-color | --ct-sys-color-error-container --ct-table-standard-error-container-color | --ct-sys-color-error-container --ct-table-surface-error-container-color |
header-container-color | transparent --ct-table-standard-header-container-color | --ct-sys-color-surface-container-lowest --ct-table-surface-header-container-color |
header-headline-color | --ct-sys-color-on-surface --ct-table-standard-header-headline-color | --ct-sys-color-on-surface --ct-table-surface-header-headline-color |
header-hover-headline-color | same as row-item-label-text-color --ct-table-standard-header-hover-headline-color | same as row-item-label-text-color --ct-table-surface-header-hover-headline-color |
header-hover-sorting-icon-button-color | same as row-item-label-text-color --ct-table-standard-header-hover-sorting-icon-button-color | same as row-item-label-text-color --ct-table-surface-header-hover-sorting-icon-button-color |
on-error-container-color | --ct-sys-color-on-error-container --ct-table-standard-on-error-container-color | --ct-sys-color-on-error-container --ct-table-surface-on-error-container-color |
outline-color | --ct-sys-color-outline-variant --ct-table-standard-outline-color | --ct-sys-color-outline-variant --ct-table-surface-outline-color |
row-item-container-color | transparent --ct-table-standard-row-item-container-color | --ct-sys-color-surface-container-lowest --ct-table-surface-row-item-container-color |
row-item-hover-label-text-color | --ct-sys-color-on-surface-hover --ct-table-standard-row-item-hover-label-text-color | --ct-sys-color-on-surface-hover --ct-table-surface-row-item-hover-label-text-color |
row-item-hover-state-layer-color | --ct-sys-color-on-surface --ct-table-standard-row-item-hover-state-layer-color | --ct-sys-color-on-surface --ct-table-surface-row-item-hover-state-layer-color |
row-item-hover-state-layer-opacity | --ct-sys-state-hover-state-layer-opacity --ct-table-standard-row-item-hover-state-layer-opacity | --ct-sys-state-hover-state-layer-opacity --ct-table-surface-row-item-hover-state-layer-opacity |
row-item-label-text-color | --ct-sys-color-on-surface --ct-table-standard-row-item-label-text-color | --ct-sys-color-on-surface --ct-table-surface-row-item-label-text-color |
row-item-outline-color | --ct-sys-color-outline-variant --ct-table-standard-row-item-outline-color | --ct-sys-color-outline-variant --ct-table-surface-row-item-outline-color |
row-item-pressed-label-text-color | --ct-sys-color-on-surface-pressed --ct-table-standard-row-item-pressed-label-text-color | --ct-sys-color-on-surface-pressed --ct-table-surface-row-item-pressed-label-text-color |
row-item-pressed-state-layer-color | same as row-item-hover-state-layer-color --ct-table-standard-row-item-pressed-state-layer-color | same as row-item-hover-state-layer-color --ct-table-surface-row-item-pressed-state-layer-color |
row-item-pressed-state-layer-opacity | --ct-sys-state-pressed-state-layer-opacity --ct-table-standard-row-item-pressed-state-layer-opacity | --ct-sys-state-pressed-state-layer-opacity --ct-table-surface-row-item-pressed-state-layer-opacity |
row-item-selected-hover-label-text-color | --ct-sys-color-on-surface-selected-hover --ct-table-standard-row-item-selected-hover-label-text-color | --ct-sys-color-on-surface-hover --ct-table-surface-row-item-selected-hover-label-text-color |
row-item-selected-hover-state-layer-color | --ct-sys-color-on-surface-selected-state-layer --ct-table-standard-row-item-selected-hover-state-layer-color | same as row-item-hover-state-layer-color --ct-table-surface-row-item-selected-hover-state-layer-color |
row-item-selected-hover-state-layer-opacity | --ct-sys-state-hover-state-layer-opacity --ct-table-standard-row-item-selected-hover-state-layer-opacity | --ct-sys-state-hover-state-layer-opacity --ct-table-surface-row-item-selected-hover-state-layer-opacity |
row-item-selected-label-text-color | same as row-item-label-text-color --ct-table-standard-row-item-selected-label-text-color | same as row-item-label-text-color --ct-table-surface-row-item-selected-label-text-color |
row-item-selected-pressed-label-text-color | --ct-sys-color-on-surface-selected-pressed --ct-table-standard-row-item-selected-pressed-label-text-color | --ct-sys-color-on-surface-pressed --ct-table-surface-row-item-selected-pressed-label-text-color |
row-item-selected-pressed-state-layer-color | --ct-sys-color-on-surface-selected-state-layer --ct-table-standard-row-item-selected-pressed-state-layer-color | --ct-sys-color-on-surface --ct-table-surface-row-item-selected-pressed-state-layer-color |
row-item-selected-pressed-state-layer-opacity | --ct-sys-state-pressed-state-layer-opacity --ct-table-standard-row-item-selected-pressed-state-layer-opacity | --ct-sys-state-pressed-state-layer-opacity --ct-table-surface-row-item-selected-pressed-state-layer-opacity |
scrollbar-color | --ct-sys-color-outline-variant --ct-table-standard-scrollbar-color | --ct-sys-color-outline-variant --ct-table-surface-scrollbar-color |
scrollbar-thumb-color | --ct-sys-color-on-surface-variant --ct-table-standard-scrollbar-thumb-color | --ct-sys-color-on-surface-variant --ct-table-surface-scrollbar-thumb-color |
scrollbar-thumb-hover-color | --ct-sys-color-on-surface --ct-table-standard-scrollbar-thumb-hover-color | --ct-sys-color-on-surface --ct-table-surface-scrollbar-thumb-hover-color |
Other tokens
These stay the same whatever the variant.
| Token | Value |
|---|---|
--ct-table-caption-text-color | --ct-sys-color-on-surface --ct-table-caption-text-color |
--ct-table-caption-text-font | --ct-sys-typescale-title-medium-font --ct-table-caption-text-font |
--ct-table-caption-text-line-height | --ct-sys-typescale-title-medium-line-height --ct-table-caption-text-line-height |
--ct-table-caption-text-size | --ct-sys-typescale-title-medium-size --ct-table-caption-text-size |
--ct-table-caption-text-tracking | --ct-sys-typescale-title-medium-tracking --ct-table-caption-text-tracking |
--ct-table-caption-text-weight | --ct-sys-typescale-title-medium-weight --ct-table-caption-text-weight |
--ct-table-footer-container-dense-1-height | 48px --ct-table-footer-container-dense-1-height |
--ct-table-footer-container-dense-2-height | 44px --ct-table-footer-container-dense-2-height |
--ct-table-footer-container-dense-3-height | 40px --ct-table-footer-container-dense-3-height |
--ct-table-footer-container-dense-4-height | 36px --ct-table-footer-container-dense-4-height |
--ct-table-footer-container-standard-height | 52px --ct-table-footer-container-standard-height |
--ct-table-header-container-dense-1-height | 52px --ct-table-header-container-dense-1-height |
--ct-table-header-container-dense-2-height | 48px --ct-table-header-container-dense-2-height |
--ct-table-header-container-dense-3-height | 44px --ct-table-header-container-dense-3-height |
--ct-table-header-container-dense-4-height | 40px --ct-table-header-container-dense-4-height |
--ct-table-header-container-standard-height | 56px --ct-table-header-container-standard-height |
--ct-table-header-headline-font | --ct-sys-typescale-title-small-font --ct-table-header-headline-font |
--ct-table-header-headline-size | --ct-sys-typescale-title-small-size --ct-table-header-headline-size |
--ct-table-header-headline-weight | --ct-sys-typescale-title-small-weight --ct-table-header-headline-weight |
--ct-table-header-sticky-offset | 0px --ct-table-header-sticky-offset |
--ct-table-outline-width | 1px --ct-table-outline-width |
--ct-table-row-item-label-text-font | --ct-sys-typescale-body-medium-font --ct-table-row-item-label-text-font |
--ct-table-row-item-label-text-size | --ct-sys-typescale-body-medium-size --ct-table-row-item-label-text-size |
--ct-table-row-item-label-text-weight | --ct-sys-typescale-body-medium-weight --ct-table-row-item-label-text-weight |
--ct-table-row-item-outline-width | 1px --ct-table-row-item-outline-width |
--ct-table-row-layers-container-dense-1-height | 48px --ct-table-row-layers-container-dense-1-height |
--ct-table-row-layers-container-dense-2-height | 44px --ct-table-row-layers-container-dense-2-height |
--ct-table-row-layers-container-dense-3-height | 40px --ct-table-row-layers-container-dense-3-height |
--ct-table-row-layers-container-dense-4-height | 36px --ct-table-row-layers-container-dense-4-height |
--ct-table-row-layers-container-standard-height | 52px --ct-table-row-layers-container-standard-height |
Names and states
A screen reader announces a data table as a table with a header row. It follows the WAI-ARIA Authoring Practices: Table pattern, a static table with no cell navigation.
- The caption is the first source of the name. Without one,
names it, and a written table falls back to its owngrid-labelaria-label. - An
aria-labelset on the data table has no effect. Give the table a caption or .grid-label - A screen reader announces the row and column counts, and reads each header cell as a column header.
- A sortable header is a button named for its column, and a screen reader announces its sort state. The sort arrow itself is not announced.
- A sort is announced in a live region, such as "Sorted by Customer, ascending". Loads announce "Loading data", "Loaded 3 rows", and "No data to display".
- Choose a data grid when readers must move between cells by keyboard or select rows. A data table has no cell roles.
Keyboard and focus
| Key | Action |
|---|---|
| Tab | Moves to the next control in the table, such as a sort button, a cell action, or your own content. |
| Shift+Tab | Moves to the previous control. |
| Enter | Activates the focused sort button or cell action. |
| Space | Activates the focused sort button or a cell action button. A cell action link takes Enter, as any link does. |
These are the keys of an ordinary button or link; the table adds no keys of its own.
- A sort button shows a focus ring on keyboard focus.
- Cells are not focusable. Only interactive content inside cells is in the Tab order.
- A table that scrolls takes one Tab stop, announced as a group named by
or "Scrollable table", so keyboard users can scroll it. A table that does not scroll takes no Tab stop.grid-label
Pointer and touch
- The sort arrow is always visible, so touch users can see that a header is interactive.
sets the touch target of the sort buttons. The default, from your style configuration, istouch-target , which makes each button as large as its header cell.overflow leaves only the visible button, andnone acts aswrapper , because the table never grows its header.overflow- Keep controls you place in cells, such as buttons from cell content, at least 24 by 24 pixels, the minimum in WCAG 2.5.8.
Display settings
- Forced colors: row dividers stay visible and take a system color.
- Reduced motion: the table has no animation, so the setting changes nothing.
- Right-to-left: text columns start at the inline edge, which is the right edge in a right-to-left layout.
Standards
With its defaults, a data table meets four WCAG 2.2 success criteria:
- 1.3.1 Info and Relationships (A)
- 2.1.1 Keyboard (A)
- 2.4.7 Focus Visible (AA)
- 4.1.2 Name, Role, Value (A)
Three more depend on how you use it:
- 1.1.1 Non-text Content (A): give every image in a cell a text alternative, or an empty
altwhen it is decorative. - 2.4.6 Headings and Labels (AA): give the table a caption or
that describes its content, and keep column titles short.grid-label - 2.5.8 Target Size (Minimum) (AA): keep every control you place in a cell at least 24 by 24 pixels.