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.
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:
How to use:
- Add
TablewithTItemandData(anyIEnumerable<TItem>). - Add one
TableColumnper column. SetHeaderText, and write the cell inside it with the row item as@context. The columns takeTItemfrom the table. - Set
IsRowHeader="true"on the column that names each row, andCaptionto name the table. - Use
TextAlignmentandHeaderTextAlignmentto align a column, for example numbers toAlignment.End.
Variants #
Color the whole table or its head with Bootstrap's table variants. Change the colors below.
How to use:
How to use:
- Set
Color(TableColor) for the table. - Set
HeaderColorfor the head, for exampleTableColor.LightorTableColor.Dark.
Accented tables #
Stripe the rows or the columns, and highlight the row under the pointer.
How to use:
How to use:
- Set
Stripedfor striped rows andStripedColumnsfor striped columns. - Set
Hoverto highlight rows on hover.
Borders #
Add borders on all sides, remove them, or change their color.
How to use:
How to use:
- Set
Borderedfor borders on every cell, orBorderlessfor none. - 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:
How to use:
- Set
Smallfor compact rows. - Set
GroupDividerfor 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:
How to use:
- Set
VerticalAlignment(TableVerticalAlignment) on the table. - Set
VerticalAlignmenton a column to override it for that column's cells. - Set
TextAlignmentfor horizontal alignment, andTextNoWrapto keep a column on one line.
Header cells #
Style a column's header cell, or replace its text with markup.
How to use:
How to use:
- Set
HeaderClassandHeaderStyleto style the column's<th>. - Use
HeaderContentinstead ofHeaderTextfor markup such as an icon; the cell then goes inChildContent.
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:
How to use:
- Set
Caption, orCaptionTemplatefor markup. - Set
CaptionTopto show it above the table, andCaptionClassto style it. - Set
VisuallyHiddenCaptionto 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:
How to use:
- Set
IsRowHeader="true"on the column; its cells render as<th scope="row">. - Use
ColumnClassto change its weight, for examplefw-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:
How to use:
- Set
RowColor(Func<TItem, TableColor>) andRowActive(Func<TItem, bool>) on the table. - Set
CellColorandCellActiveon a column for its cells. - Use
RowClassandColumnClass(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:
How to use:
- Set
Responsiveto scroll at every width, orResponsiveBreakpointto scroll only below that width. - Style the wrapper with
TableContainerClassandTableContainerStyle. - 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:
How to use:
- Put a
Tablein a column's content. - Give the inner columns their own
Contextname, such asContext="line", so it does not clash with the outercontext.
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:
- Set
Class,Style, or an attribute such asdata-testidon the table. - Use
TableContainerClassandTableContainerStylefor the responsive wrapper.
Loading and empty states #
While
How to use:
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:
- Leave
Datanulluntil the rows arrive; setLoadingTemplateto show your own content instead of the placeholders. - Set
EmptyText(default "No records to display"), orEmptyDataTemplatefor markup, for an empty list. - Footers are hidden in both states.
Footer #
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:
How to use:
- Set
FooterTexton a column, orFooterTemplatefor markup. - The footer cell follows the column's
TextAlignment.
Footer template #
Write the footer rows yourself when a label spans several columns or there is more than one footer row.
How to use:
How to use:
- Put the columns in
ChildContentand your<tr>rows in the table'sFooterTemplate. - Use
<th scope="row" colspan="…">for a label that names its row. - 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:
How to use:
- Set
RowKeySelector, for exampleRowKeySelector="ticket => ticket.Id". Keys must be unique. - 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:
How to use:
- Set
IsVisibleon the column. - Prefer it over wrapping the column in
@if: a column added back by@ifmoves 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
How to use:
Data.
How to use:
- Set
Data="items.Select((item, index) => (item, index))"andTItemto the tuple type. - Read
@context.Indexand@context.Item(or your own names) in the columns.