Data Sources Overview

The DataSource trait

All row data in rs-grid is accessed through the DataSource trait:

pub trait DataSource: Debug {
    fn row_count(&self) -> u64;
    fn get_cell(&self, row: u64, col_key: &str) -> Option<String>;
    fn clone_box(&self) -> Option<Box<dyn DataSource>>;
    fn set_cell(&mut self, row: u64, col_key: &str, value: String) { }
    fn cell_status(&self, row: u64, col_key: &str) -> CellStatus { ... }
}

This abstraction allows rs-grid to work with in-memory data, virtual (computed) data, or server-side paginated data through the same interface.

CellStatus

#[non_exhaustive]
pub enum CellStatus {
    Ready(String),  // value is available
    Loading,        // page not yet fetched (async sources)
    Absent,         // fetched but no value
}

The renderer uses CellStatus to decide whether to draw the cell value, a skeleton loading placeholder, or nothing.

Built-in implementations

SourceMemoryEditableCloneableBest for
VecDataSourceO(n)YesYesSmall to medium datasets
FnDataSourceO(1)No*NoVirtual/computed data, demos
PageCacheDataSourceO(pages)NoYesServer-side paginated data
Note

*FnDataSource is read-only, but edits still work via the patches layer in GridModel. See Data Model for details.

Client-side vs Server-side mode

Set model.mode to control where sort/filter logic runs:

model.mode = DataSourceMode::ServerSide;
ClientSide (default)ServerSide
Sortapply_sort() sorts locallyNo-op (server sorts)
Filterapply_filter() filters locallyNo-op (server filters)
SearchScans local cellsScans local cells
Row countdata.row_count()Updated via SetTotalRowCount

In server-side mode, your application is responsible for:

  1. Listening to sort/filter changes
  2. Fetching new data from the server
  3. Updating the PageCacheDataSource
  4. Sending NotifyPageLoaded to trigger re-render