A table widget with headers, rows, footer, and optional selection.
Fields
:rows- list of rows. Each row is a list of cells, and each cell accepts anyExRatatui.Text-coercible line-like value: aString.t(), a%ExRatatui.Text.Span{}, a%ExRatatui.Text.Line{}, or a list of spans. Cells are single-line — strings with embedded newlines raise.:header- optional list of header cells (same shape as row cells):footer- optional list of footer cells (same shape as row cells). Renders at the bottom of the table area.:widths- list of constraint tuples for column widths (e.g.,[{:length, 10}, {:percentage, 50}, {:min, 5}]):style-%ExRatatui.Style{}for the table:block- optional%ExRatatui.Widgets.Block{}container:highlight_style-%ExRatatui.Style{}for the selected row (row-level highlight):column_highlight_style-%ExRatatui.Style{}for the selected column.nilmeans no column highlight.:cell_highlight_style-%ExRatatui.Style{}for the selected cell (intersection of selected row + selected column).nilmeans no per-cell highlight.:header_style-%ExRatatui.Style{}applied to the header row.nilfalls back to the table's:style.:footer_style-%ExRatatui.Style{}applied to the footer row.nilfalls back to the table's:style.:highlight_symbol- string prefix for the selected row:highlight_spacing- when to reserve the highlight symbol column. One of:always,:when_selected(default — matches ratatui), or:never.:selected- zero-based index of the selected row, ornil. Must be in0..length(rows) - 1; any other value raisesArgumentErrorat render time.:selected_column- zero-based index of the selected column, ornil. Required to activate:column_highlight_styleand:cell_highlight_style— without it, the column / cell styles never fire (ratatui'sTableState::select_column/1is the gating mechanism). Must be in0..widths_count - 1.:column_spacing- spacing between columns (default: 1)
Examples
iex> %ExRatatui.Widgets.Table{
...> rows: [["Alice", "30"], ["Bob", "25"]],
...> header: ["Name", "Age"],
...> widths: [{:length, 15}, {:length, 10}]
...> }
%ExRatatui.Widgets.Table{
rows: [["Alice", "30"], ["Bob", "25"]],
header: ["Name", "Age"],
footer: nil,
widths: [length: 15, length: 10],
style: %ExRatatui.Style{},
block: nil,
highlight_style: %ExRatatui.Style{},
column_highlight_style: nil,
cell_highlight_style: nil,
header_style: nil,
footer_style: nil,
highlight_symbol: nil,
highlight_spacing: :when_selected,
selected: nil,
selected_column: nil,
column_spacing: 1
}
Summary
Types
@type cell() :: String.t() | ExRatatui.Text.Span.t() | ExRatatui.Text.Line.t() | [ExRatatui.Text.Span.t()]
@type highlight_spacing() :: :always | :when_selected | :never
@type t() :: %ExRatatui.Widgets.Table{ block: ExRatatui.Widgets.Block.t() | nil, cell_highlight_style: ExRatatui.Style.t() | nil, column_highlight_style: ExRatatui.Style.t() | nil, column_spacing: non_neg_integer(), footer: [cell()] | nil, footer_style: ExRatatui.Style.t() | nil, header: [cell()] | nil, header_style: ExRatatui.Style.t() | nil, highlight_spacing: highlight_spacing(), highlight_style: ExRatatui.Style.t(), highlight_symbol: String.t() | nil, rows: [[cell()]], selected: non_neg_integer() | nil, selected_column: non_neg_integer() | nil, style: ExRatatui.Style.t(), widths: [ExRatatui.Layout.constraint()] }