Skip to main content

DataTable

Struct DataTable 

Source
pub struct DataTable<T: Clone> { /* private fields */ }
Expand description

Main table instance that coordinates all table functionality.

Manages columns, data, and state, providing methods for sorting, filtering, pagination, selection, and all other table operations.

Implementations§

Source§

impl<T: Clone> DataTable<T>

Source

pub fn new(options: DataTableOptions) -> Self

Creates a new table with the given options.

§Parameters
  • options: The table configuration options.
§Returns
  • DataTable<T>: A new empty table instance.
Source

pub fn with_data<F>(columns: Vec<ColumnDef<T>>, data: Vec<T>, id_fn: F) -> Self
where F: Fn(&T, usize) -> DataTableRowId,

Creates a table with columns and data.

§Parameters
  • columns: The column definitions.
  • data: The raw data rows.
  • id_fn: A function that generates a row ID from row data and index.
§Returns
  • DataTable<T>: A new table with the provided columns and data.
Source

pub fn builder() -> DataTableOptionsBuilder

Creates a table builder.

§Returns
  • DataTableOptionsBuilder: A new options builder instance.
Source

pub fn set_columns(&mut self, columns: Vec<ColumnDef<T>>)

Sets the column definitions.

§Parameters
  • columns: The new column definitions.
Source

pub fn set_data<F>(&mut self, data: Vec<T>, id_fn: F)
where F: Fn(&T, usize) -> DataTableRowId,

Sets the table data.

§Parameters
  • data: The new raw data rows.
  • id_fn: A function that generates a row ID from row data and index.
Source

pub fn set_data_indexed(&mut self, data: Vec<T>)

Sets the data using index as row ID.

§Parameters
  • data: The new raw data rows.
Source

pub fn columns(&self) -> &[ColumnDef<T>]

Returns the column definitions.

§Returns
  • &[ColumnDef<T>]: A slice of column definitions.
Source

pub fn state_mut(&mut self) -> &mut DataTableState

Returns a mutable reference to the state.

§Returns
  • &mut DataTableState: A mutable reference to the table state.
Source

pub fn state(&self) -> &DataTableState

Returns the table state.

§Returns
  • &DataTableState: A reference to the table state.
Source

pub fn options(&self) -> &DataTableOptions

Returns the table options.

§Returns
  • &DataTableOptions: A reference to the table options.
Source

pub fn row_model(&self) -> &DataTableRowModel<T>

Returns the row model.

§Returns
  • &DataTableRowModel<T>: A reference to the row model.
Source

pub fn process(&mut self)

Processes the row model with current state.

Source

pub fn visible_rows(&self) -> impl Iterator<Item = &DataTableRow<T>>

Returns visible rows after processing.

§Returns
  • impl Iterator<Item = &DataTableRow<T>>: An iterator over visible rows.
Source

pub fn total_row_count(&self) -> usize

Returns the total number of rows.

§Returns
  • usize: The total row count.
Source

pub fn filtered_row_count(&self) -> usize

Returns the number of filtered rows.

§Returns
  • usize: The filtered row count.
Source

pub fn page_row_count(&self) -> usize

Returns the number of rows on the current page.

§Returns
  • usize: The page row count.
Source

pub fn get_row(&self, id: &DataTableRowId) -> Option<&DataTableRow<T>>

Gets a row by ID.

§Parameters
  • id: The row identifier to look up.
§Returns
  • Option<&DataTableRow<T>>: The row if found.
Source

pub fn visible_column_ids(&self) -> Vec<ColumnId>

Returns visible column IDs in order.

§Returns
  • Vec<ColumnId>: The ordered list of visible column IDs.
Source

pub fn visible_columns(&self) -> Vec<&ColumnDef<T>>

Returns visible columns in order.

§Returns
  • Vec<&ColumnDef<T>>: References to visible column definitions.
Source

pub fn get_column(&self, id: &ColumnId) -> Option<&ColumnDef<T>>

Gets a column by ID.

§Parameters
  • id: The column identifier to look up.
§Returns
  • Option<&ColumnDef<T>>: The column definition if found.
Source

pub fn toggle_sort(&mut self, column_id: impl Into<ColumnId>, multi: bool)

Toggles sorting for a column.

§Parameters
  • column_id: The column identifier to toggle sorting for.
  • multi: Whether to add to multi-sort list.
Source

pub fn set_column_filter( &mut self, column_id: impl Into<ColumnId>, value: impl Into<String>, )

Sets a column filter.

§Parameters
  • column_id: The column identifier.
  • value: The filter value text.
Source

pub fn set_global_filter(&mut self, value: impl Into<String>)

Sets the global filter.

§Parameters
  • value: The global search text.
Source

pub fn toggle_row_selection(&mut self, row_id: DataTableRowId)

Toggles row selection.

§Parameters
  • row_id: The row identifier to toggle selection for.
Source

pub fn select_all_rows(&mut self)

Selects all filtered rows.

Source

pub fn clear_selection(&mut self)

Clears row selection.

Source

pub fn toggle_row_expansion(&mut self, row_id: DataTableRowId)

Toggles row expansion.

§Parameters
  • row_id: The row identifier to toggle expansion for.
Source

pub fn toggle_column_visibility(&mut self, column_id: ColumnId)

Toggles column visibility.

§Parameters
  • column_id: The column identifier to toggle visibility for.
Source

pub fn go_to_page(&mut self, page: usize)

Goes to a specific page.

§Parameters
  • page: The zero-based page index.
Source

pub fn next_page(&mut self)

Goes to the next page.

Source

pub fn previous_page(&mut self)

Goes to the previous page.

Source

pub fn set_page_size(&mut self, size: usize)

Sets the page size.

§Parameters
  • size: The new page size.
Source

pub fn reset(&mut self)

Resets all table state.

Auto Trait Implementations§

§

impl<T> Freeze for DataTable<T>

§

impl<T> !RefUnwindSafe for DataTable<T>

§

impl<T> Send for DataTable<T>
where T: Send,

§

impl<T> Sync for DataTable<T>
where T: Sync,

§

impl<T> Unpin for DataTable<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for DataTable<T>

§

impl<T> !UnwindSafe for DataTable<T>

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.