pub struct GridModel<T> { /* private fields */ }Expand description
Framework-independent ordering and selection over owned records.
Selection refers to an insertion index, so sorting never selects a different record.
Implementations§
Source§impl<T> GridModel<T>
impl<T> GridModel<T>
pub fn new(columns: Vec<Column<T>>, rows: Vec<T>) -> Self
Sourcepub fn with_row_id<K: Eq + 'static>(
self,
row_id: impl Fn(&T) -> K + 'static,
) -> Self
pub fn with_row_id<K: Eq + 'static>( self, row_id: impl Fn(&T) -> K + 'static, ) -> Self
Preserve selection across replacements using an application-owned row ID. IDs must be stable and unique. A missing or duplicated selected ID clears selection. Without this callback, replacements clear selection as before. Only active/marked IDs are retained; no per-row ID index is allocated.
Sourcepub fn selected_indices(&self) -> impl Iterator<Item = usize> + '_
pub fn selected_indices(&self) -> impl Iterator<Item = usize> + '_
Resident insertion indices explicitly marked for bulk actions, in insertion order. The active cursor row is independent of this set.
pub fn is_row_selected(&self, index: usize) -> bool
Sourcepub fn set_selected_indices(
&mut self,
indices: impl IntoIterator<Item = usize>,
) -> bool
pub fn set_selected_indices( &mut self, indices: impl IntoIterator<Item = usize>, ) -> bool
Replace the bulk selection. Invalid indices are ignored.
pub fn toggle_row_selection(&mut self, index: usize) -> bool
pub fn clear_row_selection(&mut self) -> bool
Sourcepub fn visible_len(&self) -> usize
pub fn visible_len(&self) -> usize
Number of rows after filtering, independently of resident storage size.
Sourcepub fn set_filter(&mut self, filter: impl Fn(&T) -> bool + 'static)
pub fn set_filter(&mut self, filter: impl Fn(&T) -> bool + 'static)
Filter owned rows using actual record values. Search and this predicate combine.
pub fn clear_filter(&mut self)
Sourcepub fn set_search(&mut self, query: impl Into<String>)
pub fn set_search(&mut self, query: impl Into<String>)
Case-insensitive substring search across all defined formatted columns, removing terminal and bidirectional formatting controls as rendering and copying do. Formatting is evaluated for all resident rows when the query changes.
pub fn rows(&self) -> &[T]
pub fn sort(&self) -> Option<Sort>
pub fn selected(&self) -> Option<&T>
pub fn selected_index(&self) -> Option<usize>
pub fn selected_position(&self) -> Option<usize>
pub fn row_at(&self, position: usize) -> Option<&T>
Sourcepub fn index_at(&self, position: usize) -> Option<usize>
pub fn index_at(&self, position: usize) -> Option<usize>
Resolve a sorted position to the resident record’s insertion index.
Sourcepub fn update_row(&mut self, index: usize, update: impl FnOnce(&mut T)) -> bool
pub fn update_row(&mut self, index: usize, update: impl FnOnce(&mut T)) -> bool
Edit one resident record, maintaining stable sorting and selection.
Returns false for an invalid index without calling update.
Only the edited row is repositioned: logarithmic comparisons, with up to
linear index lookup/movement. Small moves shift only the crossed span
of ordering indices; the full dataset is never re-sorted.
pub fn select(&mut self, position: usize) -> bool
Sourcepub fn toggle_sort(&mut self, column: usize) -> bool
pub fn toggle_sort(&mut self, column: usize) -> bool
Cycle ascending → descending → insertion order. Returns false for unsortable columns.
Sourcepub fn replace_rows(&mut self, rows: Vec<T>)
pub fn replace_rows(&mut self, rows: Vec<T>)
Replace records, preserving the active sort and selection when a unique
matching ID is configured with Self::with_row_id.
Auto Trait Implementations§
impl<T> !RefUnwindSafe for GridModel<T>
impl<T> !Send for GridModel<T>
impl<T> !Sync for GridModel<T>
impl<T> !UnwindSafe for GridModel<T>
impl<T> Freeze for GridModel<T>
impl<T> Unpin for GridModel<T>
impl<T> UnsafeUnpin for GridModel<T>where
Vec<Column<T>>: UnsafeUnpin,
Vec<T>: UnsafeUnpin,
Option<RowIdentity<T>>: UnsafeUnpin,
Option<Box<dyn Fn(&T) -> bool>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more