Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Table

Table renders rows and columns with optional sorting, selection, and resizable columns.

When To Use It

Use Table when you need rich row/column presentation with custom cell content, sortable headers, and controlled selection for medium-sized datasets.

Constructing a Table

Table::new(cx, rows, columns, |row: &RowData| row.id)
    .sort_state(sort_state)
    .sort_cycle(TableSortCycle::TriState)
    .resizable_columns(true)
    .selectable(Selectable::Single)
    .selected_row_ids(selected_ids)
    .on_sort(|cx, key, direction| {
        cx.emit(AppEvent::SortBy(key, direction));
    })
    .on_row_select(|cx, id| {
        cx.emit(AppEvent::SelectRow(id));
    });

Define columns with TableColumn and optional header helpers:

let columns = vec![
    TableColumn::new(
        "name",
        |cx, sort| TableHeader::new(cx, "Name", sort),
        |cx, row| Label::new(cx, row.map(|r: &RowData| r.name.clone())),
    )
    .width(220.0)
    .min_width(120.0)
    .sortable(true)
    .resizable(true),
];

Table Modifiers

ModifierTypeDescriptionDefault
sort_stateimpl Res<Option<TableSortState<K>>>Controlled sort column + direction.None
resizable_columnsimpl Res<impl Into<bool>>Enables/disables column resize interactions globally.false
sort_cycleimpl Res<impl Into<TableSortCycle>>Header click sort behavior (BiState or TriState).BiState
selectableimpl Res<impl Into<Selectable>>Row selection mode.Selectable::None
selection_follows_focusimpl Res<impl Into<bool>>Select rows as focus moves.false
selected_row_idsimpl Res<[Id]>Controlled selected row IDs.empty
on_sortFn(&mut EventContext, K, TableSortDirection)Called when header requests sort change.-
on_row_selectFn(&mut EventContext, Id)Called when a row is selected.-

Core Types

  • Table
  • TableColumn
  • TableHeader
  • TableSortState
  • TableSortDirection
  • TableSortCycle

Sorting is controlled by your model: the table emits sort requests via on_sort, and you provide sorted rows back into Table::new.

Components and Styling

SelectorDescription
tableRoot table element.
table-headerIndividual column header view (TableHeader) containing title and sort indicator.
table .table-header-rowHeader row container.
table .table-header-cellHeader cell container.
table .table-header-titleHeader title label from TableHeader.
table .table-sort-indicatorSort indicator label from TableHeader.
table .table-bodyBody list container.
table .table-rowRow container.
table .table-row.odd / .evenAlternating row classes.
table .table-cellCell container.
table .table-header-cell.sortableApplied to a header cell that is sortable.
table .table-header-cell.resizableApplied to a header cell that is currently resizable.

Accessibility

  • Provide descriptive header labels and keep row selection state mirrored in model state.
  • Combine selected_row_ids and on_row_select for predictable controlled behavior.