Skip to main content

TableModel

Trait TableModel 

pub trait TableModel {
    type Row: ?Sized;

    // Required methods
    fn len(&self) -> usize;
    fn key_at(&self, index: usize) -> Option<u64>;
    fn index_of(&self, key: u64) -> Option<usize>;
    fn row_state(&self, index: usize) -> Arrival<&Self::Row, &str>;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn can_retry(&self, _index: usize) -> bool { ... }
    fn retry(&mut self, _index: usize) { ... }
    fn request_range(&mut self, _range: Range<usize>) { ... }
    fn poll_changed(&mut self) -> bool { ... }
    fn poll_changes(&mut self) -> Vec<ListModelChange<u64>> { ... }
    fn sort_by(&mut self, _column_key: &str, _ascending: bool) -> bool { ... }
    fn needs_poll(&self) -> bool { ... }
}
Expand description

Unopinionated backing model for very large or asynchronously populated tables. Implementations need not keep all rows resident: DataTable queries only the visible range plus overscan.

Required Associated Types§

type Row: ?Sized

Required Methods§

fn len(&self) -> usize

Logical row count. This may be much larger than the resident cache.

fn key_at(&self, index: usize) -> Option<u64>

Stable, unique identity for the row at index.

fn index_of(&self, key: u64) -> Option<usize>

Current index for a stable key, used to preserve anchors and selection across inserts, removals, moves, and sort changes.

fn row_state(&self, index: usize) -> Arrival<&Self::Row, &str>

Where row index’s data stands: resident, on its way (saying where it comes from), or failed with the reason. A pending row keeps its geometry and stable key, and the table paints its placeholder (crate::widget::ArrivingRows); completing a fetch disturbs neither the scroll anchor nor the selection.

Provided Methods§

fn is_empty(&self) -> bool

fn can_retry(&self, _index: usize) -> bool

Whether failed row index can be asked for again: pressing it then calls Self::retry.

fn retry(&mut self, _index: usize)

Ask again for row index after it failed.

fn request_range(&mut self, _range: Range<usize>)

Opportunity to enqueue a fetch for the visible range plus overscan.

fn poll_changed(&mut self) -> bool

Drain model notifications. Return true after any logical order, count, key, or row-state change so the table reconciles and repaints.

fn poll_changes(&mut self) -> Vec<ListModelChange<u64>>

Drain a specific model-notification batch. Existing implementations of Self::poll_changed remain compatible and produce TableModelChange::Reset. New asynchronous models should override this method so unchanged retained cell controls survive background updates.

fn sort_by(&mut self, _column_key: &str, _ascending: bool) -> bool

Apply a model-owned sort. Return true when the logical order changed synchronously or a remote sort request was accepted.

fn needs_poll(&self) -> bool

Whether the host should keep scheduling frames so poll_changed can observe an in-flight asynchronous source.

Implementors§