DataTable
Flexible, accessible data table with sorting, pagination, multi-selection, and keyboard navigation.
Installation
Add the DataTable component using the CLI:
Usage
Basic data table with items and columns. Use Items to provide data, Columns to define columns with a Field expression or CellTemplate for custom rendering. Set Hover for row hover effect and Label for accessibility.
| Name | Status | |
|---|---|---|
| Alice Johnson | alice@example.com | Active |
| Bob Smith | bob@example.com | Inactive |
| Carol Williams | carol@example.com | Active |
| David Brown | david@example.com | Pending |
| Eve Davis | eve@example.com | Active |
Examples
Sortable Columns
Add the Sortable attribute to columns to enable sorting. Click column headers to toggle sort direction. The table handles sorting automatically if items are sortable collections.
| Name | Status | Score | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Active | 92 |
| Bob Smith | bob@example.com | Inactive | 45 |
| Carol Williams | carol@example.com | Active | 78 |
| David Brown | david@example.com | Pending | 61 |
| Eve Davis | eve@example.com | Active | 88 |
Custom Cell Templates
Use CellTemplate to customize how column values are rendered. Access the row item via context. Useful for formatting, badges, relative dates, or complex layouts within cells.
| Name | Status | Joined | Score |
|---|---|---|---|
| Alice Johnson | Active | 2y ago | 92 |
| Bob Smith | Inactive | 3y ago | 45 |
| Carol Williams | Active | 2y ago | 78 |
| David Brown | Pending | 2y ago | 61 |
| Eve Davis | Active | 4y ago | 88 |
Dense & Striped
Use Dense for compact row heights and Striped for alternating row backgrounds. Both improve readability with different visual styles. Combine with Hover for interactive feel.
| Name | Status | Score | Joined | |
|---|---|---|---|---|
| Alice Johnson | alice@example.com | Active | 92 | 2023-03-12 |
| Bob Smith | bob@example.com | Inactive | 45 | 2022-11-05 |
| Carol Williams | carol@example.com | Active | 78 | 2024-01-20 |
| David Brown | david@example.com | Pending | 61 | 2023-07-08 |
| Eve Davis | eve@example.com | Active | 88 | 2021-09-30 |
Toolbar & Filtering
Add custom content above the table using ToolBarContent. Perfect for filters, search inputs, or action buttons. Bind to component state to filter Items reactively.
People
| Name | Status | |
|---|---|---|
| Alice Johnson | alice@example.com | Active |
| Bob Smith | bob@example.com | Inactive |
| Carol Williams | carol@example.com | Active |
| David Brown | david@example.com | Pending |
| Eve Davis | eve@example.com | Active |
| Frank Miller | frank@example.com | Inactive |
| Grace Wilson | grace@example.com | Active |
Loading State
Set IsLoading="true" to show skeleton rows instead of data. Useful while fetching data from an API. Disable this flag when data is ready.
| Name | Status | |
|---|---|---|
| Alice Johnson | alice@example.com | Active |
| Bob Smith | bob@example.com | Inactive |
| Carol Williams | carol@example.com | Active |
| David Brown | david@example.com | Pending |
| Eve Davis | eve@example.com | Active |
Empty State
When Items is empty, the table shows a default empty message. Customize it with EmptyContent to show a branded or contextual message.
Default
| Name | |
|---|---|
| No results. | |
Custom
| Name | |
|---|---|
🫙
Nothing here yet Add some people to get started. | |
Row Click
Wire up OnRowClick to handle clicks on table rows. The callback receives the clicked row's data item, enabling drill-down navigation or row selection.
| Name | Status | |
|---|---|---|
| Alice Johnson | alice@example.com | Active |
| Bob Smith | bob@example.com | Inactive |
| Carol Williams | carol@example.com | Active |
| David Brown | david@example.com | Pending |
| Eve Davis | eve@example.com | Active |
Async Data Loading
Load data asynchronously in OnInitializedAsync. Set IsLoading="true" while fetching, then update Items when ready. The table automatically re-renders with the new data.
People
| Name | Role | Experience | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Engineer | 8 years |
| Bob Smith | bob@example.com | Designer | 5 years |
| Carol Williams | carol@example.com | Engineer | 10 years |
| David Brown | david@example.com | Manager | 12 years |
| Eve Davis | eve@example.com | Engineer | 6 years |
| Frank Miller | frank@example.com | Designer | 3 years |
| Grace Wilson | grace@example.com | Engineer | 9 years |
| Hank Moore | hank@example.com | Manager | 15 years |
Multi-Selection
Set MultiSelection="true" to enable checkboxes. Use @bind-SelectedItems for two-way binding to track selected rows. Click rows or checkboxes to select; the header checkbox selects all.
People
| Name | Status | Score | ||
|---|---|---|---|---|
| Alice Johnson | alice@example.com | Active | 92 | |
| Bob Smith | bob@example.com | Inactive | 45 | |
| Carol Williams | carol@example.com | Active | 78 | |
| David Brown | david@example.com | Pending | 61 | |
| Eve Davis | eve@example.com | Active | 88 |
Grid Mode
Set InteractionMode="DataTableInteractionMode.Grid" for keyboard-driven row navigation. Use Arrow Up/Down to move between rows, Space to select, Enter to activate, and Home/End to jump. Useful for accessibility-first applications.
| Name | Status | Score | ||
|---|---|---|---|---|
| Alice Johnson | alice@example.com | Active | 92 | |
| Bob Smith | bob@example.com | Inactive | 45 | |
| Carol Williams | carol@example.com | Active | 78 | |
| David Brown | david@example.com | Pending | 61 | |
| Eve Davis | eve@example.com | Active | 88 |
Grid selection: 0 row(s)
Tip: Use Arrow Up/Down to navigate, Home/End to jump, Enter to click, Space to select.
API Reference
DataTable`1
Properties
| Name | Type | Description |
|---|---|---|
Columns |
RenderFragment |
|
Dense |
bool |
|
EmptyContent |
RenderFragment |
|
EnableDebugLogging |
bool |
|
Hover |
bool |
|
InteractionMode |
DataTableInteractionMode |
|
IsLoading |
bool |
|
Items |
IReadOnlyList<T> |
|
Label |
string |
|
MultiSelection |
bool |
|
OnRowClick |
EventCallback<T> |
|
PageSize |
int |
|
PageSizeOptions |
Int32[] |
|
SelectedItems |
HashSet<T> |
|
SelectedItemsChanged |
EventCallback<HashSet<T>> |
|
Striped |
bool |
|
ToolBarContent |
RenderFragment |
Events
| Name | Type | Description |
|---|---|---|
OnRowClick |
EventCallback<T> |
|
SelectedItemsChanged |
EventCallback<HashSet<T>> |
Methods
| Method | Returns | Description |
|---|---|---|
Equals |
bool |
|
GetHashCode |
int |
|
GetType |
Type |
|
SetParametersAsync |
Task |
|
ToString |
string |