pub struct TableState<D: TableDelegate> {
pub loop_selection: bool,
pub col_selectable: bool,
pub row_selectable: bool,
pub cell_selectable: bool,
pub row_header: bool,
pub sortable: bool,
pub col_resizable: bool,
pub col_movable: bool,
pub col_fixed: bool,
pub vertical_scroll_handle: UniformListScrollHandle,
pub horizontal_scroll_handle: VirtualListScrollHandle,
/* private fields */
}Fields§
§loop_selection: boolWhether the table can loop selection, default is true.
When the prev/next selection is out of the table bounds, the selection will loop to the other side.
col_selectable: boolWhether the table can select column.
row_selectable: boolWhether the table can select row.
cell_selectable: boolWhether the table can select cell, default is false.
When enabled:
- Users can click on individual cells to select them
- A row header column appears on the left for selecting entire rows
(can be hidden via
Self::row_header) - Keyboard navigation works at the cell level (arrow keys move between cells)
- Right-click and double-click events are supported for cells
row_header: boolWhether the row header column is visible when cell_selectable is enabled,
default is true.
Set to false to hide the narrow leftmost header column while keeping cell
selection — useful when you want to put your own content (e.g. a row index
column) on the left. When hidden, clicking the already-selected cell again
escalates the selection to the whole row so users can still pick rows; row
escalation requires row_selectable to be enabled.
sortable: boolWhether the table can sort.
col_resizable: boolWhether the table can resize columns.
col_movable: boolWhether the table can move columns.
col_fixed: boolEnable/disable fixed columns feature.
vertical_scroll_handle: UniformListScrollHandle§horizontal_scroll_handle: VirtualListScrollHandleImplementations§
Source§impl<D> TableState<D>where
D: TableDelegate,
impl<D> TableState<D>where
D: TableDelegate,
Sourcepub fn new(delegate: D, _: &mut Window, cx: &mut Context<'_, Self>) -> Self
pub fn new(delegate: D, _: &mut Window, cx: &mut Context<'_, Self>) -> Self
Create a new TableState with the given delegate.
Sourcepub fn delegate_mut(&mut self) -> &mut D
pub fn delegate_mut(&mut self) -> &mut D
Returns a mutable reference to the delegate.
Sourcepub fn loop_selection(self, loop_selection: bool) -> Self
pub fn loop_selection(self, loop_selection: bool) -> Self
Set to loop selection, default to true.
Sourcepub fn col_movable(self, col_movable: bool) -> Self
pub fn col_movable(self, col_movable: bool) -> Self
Set to enable/disable column movable, default to true.
Sourcepub fn col_resizable(self, col_resizable: bool) -> Self
pub fn col_resizable(self, col_resizable: bool) -> Self
Set to enable/disable column resizable, default to true.
Sourcepub fn sortable(self, sortable: bool) -> Self
pub fn sortable(self, sortable: bool) -> Self
Set to enable/disable column sortable, default true
Sourcepub fn row_selectable(self, row_selectable: bool) -> Self
pub fn row_selectable(self, row_selectable: bool) -> Self
Set to enable/disable row selectable, default true
Sourcepub fn col_selectable(self, col_selectable: bool) -> Self
pub fn col_selectable(self, col_selectable: bool) -> Self
Set to enable/disable column selectable, default true
Sourcepub fn cell_selectable(self, cell_selectable: bool) -> Self
pub fn cell_selectable(self, cell_selectable: bool) -> Self
Set to enable/disable cell selection, default is false.
When enabled:
- Individual cells become selectable by clicking
- A row header column appears on the left side (can be hidden via
Self::row_header) - Keyboard navigation operates at the cell level
- Cell-specific events (SelectCell, DoubleClickedCell, RightClickedCell) are emitted
§Example
let table_state = cx.new(|cx| {
TableState::new(delegate, cx)
.cell_selectable(true) // Enable cell selection
.row_selectable(true) // Also allow row selection via row header
});Sourcepub fn row_header(self, row_header: bool) -> Self
pub fn row_header(self, row_header: bool) -> Self
Set whether the row header column is shown, default is true.
Only effective when cell_selectable is true — otherwise the row header
column is never rendered. Hide it when you want to use the leftmost column
for your own content (e.g. a row index column).
When hidden, the first click on a cell selects the cell; clicking the
already-selected cell again escalates to selecting the whole row, so users
can still pick rows without the dedicated header column. The row escalation
requires row_selectable to be enabled.
Sourcepub fn refresh(&mut self, cx: &mut Context<'_, Self>)
pub fn refresh(&mut self, cx: &mut Context<'_, Self>)
When we update columns or rows, we need to refresh the table.
Sourcepub fn scroll_to_row(&mut self, row_ix: usize, cx: &mut Context<'_, Self>)
pub fn scroll_to_row(&mut self, row_ix: usize, cx: &mut Context<'_, Self>)
Scroll to the row at the given index.
pub fn scroll_to_col(&mut self, col_ix: usize, cx: &mut Context<'_, Self>)
Sourcepub fn selected_row(&self) -> Option<usize>
pub fn selected_row(&self) -> Option<usize>
Returns the selected row index.
Sourcepub fn set_selected_row(&mut self, row_ix: usize, cx: &mut Context<'_, Self>)
pub fn set_selected_row(&mut self, row_ix: usize, cx: &mut Context<'_, Self>)
Sets the selected row to the given index.
Sourcepub fn right_clicked_row(&self) -> Option<usize>
pub fn right_clicked_row(&self) -> Option<usize>
Returns the row that has been right clicked.
Sourcepub fn set_right_clicked_row(
&mut self,
row: Option<usize>,
cx: &mut Context<'_, Self>,
)
pub fn set_right_clicked_row( &mut self, row: Option<usize>, cx: &mut Context<'_, Self>, )
Set or clear the right-clicked row state.
Pass None to clear — useful when opening a header context menu
to prevent the row context menu from appearing simultaneously.
Sourcepub fn selected_col(&self) -> Option<usize>
pub fn selected_col(&self) -> Option<usize>
Returns the selected column index.
Sourcepub fn set_selected_col(&mut self, col_ix: usize, cx: &mut Context<'_, Self>)
pub fn set_selected_col(&mut self, col_ix: usize, cx: &mut Context<'_, Self>)
Sets the selected col to the given index.
Sourcepub fn selected_cell(&self) -> Option<(usize, usize)>
pub fn selected_cell(&self) -> Option<(usize, usize)>
Sourcepub fn set_selected_cell(
&mut self,
row_ix: usize,
col_ix: usize,
cx: &mut Context<'_, Self>,
)
pub fn set_selected_cell( &mut self, row_ix: usize, col_ix: usize, cx: &mut Context<'_, Self>, )
Sets the selected cell to the given row and column indices.
This method:
- Switches the table to cell selection mode
- Scrolls to make the cell visible (centered vertically)
- Emits a
TableEvent::SelectCellevent
§Example
// Select the cell at row 5, column 3
table_state.update(cx, |state, cx| {
state.set_selected_cell(5, 3, cx);
});Sourcepub fn clear_selection(&mut self, cx: &mut Context<'_, Self>)
pub fn clear_selection(&mut self, cx: &mut Context<'_, Self>)
Clear the selection of the table.
Sourcepub fn visible_range(&self) -> &TableVisibleRange
pub fn visible_range(&self) -> &TableVisibleRange
Returns the visible range of the rows and columns.
See TableVisibleRange.
Sourcepub fn headers(&self, cx: &App) -> Vec<String>
pub fn headers(&self, cx: &App) -> Vec<String>
Dump the header row of the table.
Batched exporters can read the headers once with this, then stream the
rows with Self::dump_range.
Sourcepub fn dump(&self, cx: &App) -> (Vec<String>, Vec<Vec<String>>)
pub fn dump(&self, cx: &App) -> (Vec<String>, Vec<Vec<String>>)
Dump table data.
Returns a tuple of (headers, rows) where each row is a vector of cell values.
This materializes the complete table in memory. For large tables, prefer
Self::dump_range and process rows in batches.
Sourcepub fn dump_range(
&self,
range: Range<usize>,
cx: &App,
) -> (Vec<String>, Vec<Vec<String>>)
pub fn dump_range( &self, range: Range<usize>, cx: &App, ) -> (Vec<String>, Vec<Vec<String>>)
Dump table data for the specified row range.
Returns the same (headers, rows) shape as Self::dump, with only
the rows inside the clamped range.
The requested range is clamped to the table’s current row count. For large tables, callers can invoke this repeatedly with bounded ranges.
Sourcepub fn refresh_header_layout(&mut self, cx: &mut Context<'_, Self>)
pub fn refresh_header_layout(&mut self, cx: &mut Context<'_, Self>)
Re-compute the header layout from the current delegate.
Call this after changing delegate state that affects group_headers.
Trait Implementations§
impl<D> EventEmitter<TableEvent> for TableState<D>where
D: TableDelegate,
Source§impl<D> Focusable for TableState<D>where
D: TableDelegate,
impl<D> Focusable for TableState<D>where
D: TableDelegate,
Source§fn focus_handle(&self, _cx: &App) -> FocusHandle
fn focus_handle(&self, _cx: &App) -> FocusHandle
Source§impl<D> Render for TableState<D>where
D: TableDelegate,
impl<D> Render for TableState<D>where
D: TableDelegate,
Auto Trait Implementations§
impl<D> !RefUnwindSafe for TableState<D>
impl<D> !Send for TableState<D>
impl<D> !Sync for TableState<D>
impl<D> !UnwindSafe for TableState<D>
impl<D> Freeze for TableState<D>where
D: Freeze,
impl<D> Unpin for TableState<D>where
D: Unpin,
impl<D> UnsafeUnpin for TableState<D>where
D: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more