Showcase

Blazor Table

The Blazor Bootstrap Table component renders a read-only Bootstrap 5.3 table from a list, with declared columns. The examples below cover variants, accented rows, borders, alignment, captions, row headers, row and cell colors, responsive scrolling and nesting.
API Documentation
INFO
Table renders a read-only Bootstrap 5.3 table from a list, one row per item, with columns declared as TableColumn children. It is the lightweight sibling of Grid: use Grid when you need paging, sorting, filtering, selection, or a data provider. Every option maps to a Bootstrap class, so the table follows the light and dark themes and needs no JavaScript.

Need paging, sorting or filtering? See the Grid examples.

Basic usage #

A table with a caption, a row header, and a right-aligned amount column. Cells can hold other components, such as a badge.
How to use:
  1. Add Table with TItem and Data (any IEnumerable<TItem>).
  2. Add one TableColumn per column. Set HeaderText, and write the cell inside it with the row item as @context. The columns take TItem from the table.
  3. Set IsRowHeader="true" on the column that names each row, and Caption to name the table.
  4. Use TextAlignment and HeaderTextAlignment to align a column, for example numbers to Alignment.End.

Variants #

Color the whole table or its head with Bootstrap's table variants. Change the colors below.
How to use:
  1. Set Color (TableColor) for the table.
  2. Set HeaderColor for the head, for example TableColor.Light or TableColor.Dark.

Accented tables #

Stripe the rows or the columns, and highlight the row under the pointer.
How to use:
  1. Set Striped for striped rows and StripedColumns for striped columns.
  2. Set Hover to highlight rows on hover.

Borders #

Add borders on all sides, remove them, or change their color.
How to use:
  1. Set Bordered for borders on every cell, or Borderless for none.
  2. Set BorderColor (TableBorderColor), which includes the subtle colors, black, and white.

Small and group divider #

Halve the cell padding, and put a thicker border between the head and the body.
How to use:
  1. Set Small for compact rows.
  2. Set GroupDivider for the thicker border above the body.

Alignment #

Align cells vertically for the whole table, and override one column. Change the table's alignment below; the last column stays at the bottom.
How to use:
  1. Set VerticalAlignment (TableVerticalAlignment) on the table.
  2. Set VerticalAlignment on a column to override it for that column's cells.
  3. Set TextAlignment for horizontal alignment, and TextNoWrap to keep a column on one line.

Header cells #

Style a column's header cell, or replace its text with markup.
How to use:
  1. Set HeaderClass and HeaderStyle to style the column's <th>.
  2. Use HeaderContent instead of HeaderText for markup such as an icon; the cell then goes in ChildContent.

Caption #

A caption works like a heading for the table and names it for screen readers. Move it above the table or hide it visually below.
How to use:
  1. Set Caption, or CaptionTemplate for markup.
  2. Set CaptionTop to show it above the table, and CaptionClass to style it.
  3. Set VisuallyHiddenCaption to keep it for screen readers only when a visible heading already names the table.

Row headers #

Any column can name its rows. Screen readers then announce that cell with every other cell in the row.
How to use:
  1. Set IsRowHeader="true" on the column; its cells render as <th scope="row">.
  2. Use ColumnClass to change its weight, for example fw-normal.

Row and cell colors #

Color or activate a row or a single cell from the row's data. Colors must never be the only way the meaning is shown, so the last column says it in words.
How to use:
  1. Set RowColor (Func<TItem, TableColor>) and RowActive (Func<TItem, bool>) on the table.
  2. Set CellColor and CellActive on a column for its cells.
  3. Use RowClass and ColumnClass (Func<TItem, string>) for any other class.

Responsive #

A wide table scrolls horizontally inside its own wrapper instead of widening the page. Keyboard users can focus the wrapper and scroll it with the arrow keys.
How to use:
  1. Set Responsive to scroll at every width, or ResponsiveBreakpoint to scroll only below that width.
  2. Style the wrapper with TableContainerClass and TableContainerStyle.
  3. Set a Caption (it can be visually hidden): it also names the scrolling region for screen readers.

Nesting #

A table inside a cell keeps its own styles; the outer table's color, stripes, and borders do not reach it.
How to use:
  1. Put a Table in a column's content.
  2. Give the inner columns their own Context name, such as Context="line", so it does not clash with the outer context.

Classes and attributes #

Class, Style, and any other attribute always go on the <table> element, whether or not the table is responsive.
How to use:
  1. Set Class, Style, or an attribute such as data-testid on the table.
  2. Use TableContainerClass and TableContainerStyle for the responsive wrapper.

Loading and empty states #

While Data is null, the table shows placeholder rows under its header; when the list is empty, it shows one row with a message. Use the buttons to switch states.
How to use:
  1. Leave Data null until the rows arrive; set LoadingTemplate to show your own content instead of the placeholders.
  2. Set EmptyText (default "No records to display"), or EmptyDataTemplate for markup, for an empty list.
  3. Footers are hidden in both states.
Give columns a footer cell for totals. The footer row appears when at least one column has a footer; other columns get an empty cell.
How to use:
  1. Set FooterText on a column, or FooterTemplate for markup.
  2. The footer cell follows the column's TextAlignment.
Write the footer rows yourself when a label spans several columns or there is more than one footer row.
How to use:
  1. Put the columns in ChildContent and your <tr> rows in the table's FooterTemplate.
  2. Use <th scope="row" colspan="…"> for a label that names its row.
  3. It replaces the per-column footers and is hidden while loading or empty.

Row keys #

Key rows by a record's ID so they are kept, not re-created, when the same records come back as new instances. Type a note, then refresh.
How to use:
  1. Set RowKeySelector, for example RowKeySelector="ticket => ticket.Id". Keys must be unique.
  2. Without it, rows have no key and are matched by position, so lists with equal items work as they are.

Column visibility #

Hide and show columns. A hidden column renders no header, cell, or footer cell.
How to use:
  1. Set IsVisible on the column.
  2. Prefer it over wrapping the column in @if: a column added back by @if moves to the end.

Row index #

A column's content receives the row item only. To show a rank or a row number, pair each item with its index in Data.
How to use:
  1. Set Data="items.Select((item, index) => (item, index))" and TItem to the tuple type.
  2. Read @context.Index and @context.Item (or your own names) in the columns.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.