Skip to main content

TableState

Struct TableState 

Source
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: bool

Whether 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: bool

Whether the table can select column.

§row_selectable: bool

Whether the table can select row.

§cell_selectable: bool

Whether 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: bool

Whether 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: bool

Whether the table can sort.

§col_resizable: bool

Whether the table can resize columns.

§col_movable: bool

Whether the table can move columns.

§col_fixed: bool

Enable/disable fixed columns feature.

§vertical_scroll_handle: UniformListScrollHandle§horizontal_scroll_handle: VirtualListScrollHandle

Implementations§

Source§

impl<D> TableState<D>
where D: TableDelegate,

Source

pub fn new(delegate: D, _: &mut Window, cx: &mut Context<'_, Self>) -> Self

Create a new TableState with the given delegate.

Source

pub fn delegate(&self) -> &D

Returns a reference to the delegate.

Source

pub fn delegate_mut(&mut self) -> &mut D

Returns a mutable reference to the delegate.

Source

pub fn loop_selection(self, loop_selection: bool) -> Self

Set to loop selection, default to true.

Source

pub fn col_movable(self, col_movable: bool) -> Self

Set to enable/disable column movable, default to true.

Source

pub fn col_resizable(self, col_resizable: bool) -> Self

Set to enable/disable column resizable, default to true.

Source

pub fn sortable(self, sortable: bool) -> Self

Set to enable/disable column sortable, default true

Source

pub fn row_selectable(self, row_selectable: bool) -> Self

Set to enable/disable row selectable, default true

Source

pub fn col_selectable(self, col_selectable: bool) -> Self

Set to enable/disable column selectable, default true

Source

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
});
Source

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.

Source

pub fn refresh(&mut self, cx: &mut Context<'_, Self>)

When we update columns or rows, we need to refresh the table.

Source

pub fn scroll_to_row(&mut self, row_ix: usize, cx: &mut Context<'_, Self>)

Scroll to the row at the given index.

Source

pub fn scroll_to_col(&mut self, col_ix: usize, cx: &mut Context<'_, Self>)

Source

pub fn selected_row(&self) -> Option<usize>

Returns the selected row index.

Source

pub fn set_selected_row(&mut self, row_ix: usize, cx: &mut Context<'_, Self>)

Sets the selected row to the given index.

Source

pub fn right_clicked_row(&self) -> Option<usize>

Returns the row that has been right clicked.

Source

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.

Source

pub fn selected_col(&self) -> Option<usize>

Returns the selected column index.

Source

pub fn set_selected_col(&mut self, col_ix: usize, cx: &mut Context<'_, Self>)

Sets the selected col to the given index.

Source

pub fn selected_cell(&self) -> Option<(usize, usize)>

Returns the selected cell as (row_ix, col_ix).

Returns None if no cell is currently selected or if the table is in row/column selection mode.

§Example
if let Some((row_ix, col_ix)) = table_state.read(cx).selected_cell() {
    println!("Selected cell: ({}, {})", row_ix, col_ix);
}
Source

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::SelectCell event
§Example
// Select the cell at row 5, column 3
table_state.update(cx, |state, cx| {
    state.set_selected_cell(5, 3, cx);
});
Source

pub fn clear_selection(&mut self, cx: &mut Context<'_, Self>)

Clear the selection of the table.

Source

pub fn visible_range(&self) -> &TableVisibleRange

Returns the visible range of the rows and columns.

See TableVisibleRange.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl<D> EventEmitter<TableEvent> for TableState<D>
where D: TableDelegate,

Source§

impl<D> Focusable for TableState<D>
where D: TableDelegate,

Source§

fn focus_handle(&self, _cx: &App) -> FocusHandle

Returns the focus handle associated with this view.
Source§

impl<D> Render for TableState<D>
where D: TableDelegate,

Source§

fn render( &mut self, window: &mut Window, cx: &mut Context<'_, Self>, ) -> impl IntoElement

Render this view into an element tree.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more