Skip to Content
WidgetsTable

Table

Table is the main structured-data widget.

Table
Table terminal preview
Terminal preview of Table

Smallest example

let rows = vec![ Row::new(["ansiq", "ready"]), Row::new(["monitor", "streaming"]), ]; let table = Table::new(rows, [Constraint::Percentage(50), Constraint::Percentage(50)]) .header(Row::new(["Name", "Status"])) .selected(Some(0)) .on_select(|index| Some(Message::SelectRow(index))) .build();

Use Table when

  • the data is naturally row/column shaped
  • selection state matters
  • columns need explicit width control

Key builder methods

  • Table::new(rows, widths)
  • .header(...), .footer(...)
  • .widths(...), .column_spacing(...), .flex(...)
  • .selected(...), .state(...)
  • .highlight_symbol(...), .row_highlight_style(...)
  • .on_select(...)

State object

Use TableState when row selection, column selection, or offset should be explicit:

let state = TableState::new() .with_selected(Some(0)) .with_selected_column(Some(0)) .with_offset(0); let table = Table::new(rows, widths).state(state).build();

Where to see it in examples

Last updated on