Guide API
Skip to main content

TableModel

Trait TableModel 

Source
pub trait TableModel {
    // Required methods
    fn row_count(&self) -> usize;
    fn cell(&self, row: usize, col: usize) -> Cow<'_, str>;
    fn row_key(&self, row: usize) -> RowKey;

    // Provided methods
    fn sort_key(&self, row: usize, col: usize) -> SortKey { ... }
    fn row_role(&self, _row: usize) -> Option<Role> { ... }
    fn set_cell(
        &mut self,
        _row: usize,
        _col: usize,
        _text: &str,
    ) -> Result<(), String> { ... }
}
Expand description

The rows a Table shows.

The table never reorders the model: it keeps its own row permutation for the current sort. Implement this over your own records to avoid copying them into strings up front; VecModel covers the plain-strings case.

Required Methods§

Source

fn row_count(&self) -> usize

Number of rows.

Source

fn cell(&self, row: usize, col: usize) -> Cow<'_, str>

The text of cell (row, col). An out-of-range column yields "".

Source

fn row_key(&self, row: usize) -> RowKey

Stable identity of a row; focus and selection follow the key across reloads.

Provided Methods§

Source

fn sort_key(&self, row: usize, col: usize) -> SortKey

Sort key of cell (row, col). The default parses the cell as a number and falls back to its text; override it when the displayed text is not what should sort ("10.2%", "3 days ago").

Source

fn row_role(&self, _row: usize) -> Option<Role>

Optional theme role for the whole row (e.g. a dimmed or an error row). It replaces only the normal row colour: the focused and the selected colours still win.

Source

fn set_cell( &mut self, _row: usize, _col: usize, _text: &str, ) -> Result<(), String>

Store text in cell (row, col) — a cell editor committing on an editable column. Err(message) refuses the text: the table shows message in an error box and keeps the editor open. The default refuses every edit with "read-only".

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§