leptos_struct_table

Trait TableDataProvider

Source
pub trait TableDataProvider<Row, Err: Debug = String> {
    const CHUNK_SIZE: Option<usize> = None;

    // Required method
    async fn get_rows(
        &self,
        range: Range<usize>,
    ) -> Result<(Vec<Row>, Range<usize>), Err>;

    // Provided methods
    async fn row_count(&self) -> Option<usize> { ... }
    fn set_sorting(&mut self, sorting: &VecDeque<(usize, ColumnSort)>) { ... }
    fn track(&self) { ... }
}
Expand description

The trait that provides data for the <TableContent> component. Anything that is passed to the rows prop must implement this trait.

If you add #[table(impl_vec_data_provider)] to your row struct, this is automatically implemented for Vec<Row>. This way a simple list of items can be passed to the table.

This is also automatically implemented for any struct that implements PaginatedTableDataProvider or [ExactTableDataProvider]. The first is a more convenient way of connecting to a paginated data source and the second is more convenient if you know you’re always going to return exactly the requested range (except maybe at the end of the data).

Provided Associated Constants§

Source

const CHUNK_SIZE: Option<usize> = None

If Some(…), data will be loaded in chunks of this size. This is useful for paginated data sources. If you have such a paginated data source, you probably want to implement PaginatedTableDataProvider instead of this trait.

Required Methods§

Source

async fn get_rows( &self, range: Range<usize>, ) -> Result<(Vec<Row>, Range<usize>), Err>

Get all data rows for the table specified by the range. This method is called when the table is rendered. The range is determined by the visible rows and used to virtualize the table. The parameter range is only determined by visibility and may be out of bounds. It is the responsibility of the implementation to handle this case. Use get_vec_range_clamped to get a range that is clamped to the length of the vector.

It returns a Vec of all rows loaded and the range that these rows cover. Depending on the data source you might not be able to load exactly the requested range; that’s why the actual loaded range is returned in addition to the rows. You should always return at least the range that is requested or more. If you return less rows than requested, it is assumed that the data source is done and there are no more rows to load.

In the case of an error the returned error String is going to be displayed in a in place of the failed rows.

Provided Methods§

Source

async fn row_count(&self) -> Option<usize>

The total number of rows in the table. Returns None if unknown (which is the default).

Source

fn set_sorting(&mut self, sorting: &VecDeque<(usize, ColumnSort)>)

Set the sorting of the table. The sorting is a list of column names and the sort order sorted by priority. The first entry in the list is the most important one. The default implementation does nothing. For example: [(0, ColumnSort::Ascending), (1, ColumnSort::Descending)] will sort by name first and then by age. Please note that after calling this method, data will be reloaded through get_rows.

Source

fn track(&self)

Call .track() in this method on all signals that loading data relies on. For example a search of filters. Please check the paginated_rest_datasource example

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Row, Err, D> TableDataProvider<Row, Err> for D
where D: PaginatedTableDataProvider<Row, Err>, Err: Debug,