pub struct TableState {
pub headers: Vec<String>,
pub rows: Vec<Vec<String>>,
pub selected: usize,
pub sort_column: Option<usize>,
pub sort_ascending: bool,
pub filter: String,
pub page: usize,
pub page_size: usize,
/* private fields */
}Expand description
State for a data table widget.
Pass a mutable reference to Context::table each frame. Up/Down arrow
keys move the row selection when the widget is focused. Column widths are
computed automatically from header and cell content.
Fields§
§headers: Vec<String>Column header labels.
rows: Vec<Vec<String>>Table rows, each a Vec of cell strings.
selected: usizeIndex of the currently selected row.
sort_column: Option<usize>Sorted column index (None means no sorting).
sort_ascending: boolSort direction (true for ascending).
filter: StringCase-insensitive substring filter applied across all cells.
page: usizeCurrent page (0-based) when pagination is enabled.
page_size: usizeRows per page (0 disables pagination).
Implementations§
Source§impl TableState
impl TableState
Sourcepub fn new(
headers: Vec<impl Into<String>>,
rows: Vec<Vec<impl Into<String>>>,
) -> Self
pub fn new( headers: Vec<impl Into<String>>, rows: Vec<Vec<impl Into<String>>>, ) -> Self
Create a table with headers and rows. Column widths are computed immediately.
Sourcepub fn set_rows(&mut self, rows: Vec<Vec<impl Into<String>>>)
pub fn set_rows(&mut self, rows: Vec<Vec<impl Into<String>>>)
Replace all rows, preserving the selection index if possible.
If the current selection is beyond the new row count, it is clamped to the last row.
Sourcepub fn toggle_sort(&mut self, column: usize)
pub fn toggle_sort(&mut self, column: usize)
Sort by a specific column index. If already sorted by this column, toggles direction.
Sourcepub fn sort_by(&mut self, column: usize)
pub fn sort_by(&mut self, column: usize)
Sort by column without toggling (always sets to ascending first).
Sourcepub fn set_filter(&mut self, filter: impl Into<String>)
pub fn set_filter(&mut self, filter: impl Into<String>)
Set the filter string. Multiple space-separated tokens are AND’d together — all tokens must match across any cell in the same row. Empty string disables filtering.
Sourcepub fn clear_sort(&mut self)
pub fn clear_sort(&mut self)
Clear sorting.
Sourcepub fn total_pages(&self) -> usize
pub fn total_pages(&self) -> usize
Total number of pages based on filtered rows and page_size. Returns 1 if page_size is 0.
Sourcepub fn visible_indices(&self) -> &[usize]
pub fn visible_indices(&self) -> &[usize]
Get the visible row indices after filtering and sorting (used internally by table()).
Sourcepub fn selected_row(&self) -> Option<&[String]>
pub fn selected_row(&self) -> Option<&[String]>
Get the currently selected row data, or None if the table is empty.