pub struct TableModel<T: 'static> { /* private fields */ }Expand description
A native table backed by rows of T. See the module docs.
Implementations§
Source§impl<T: 'static> TableModel<T>
impl<T: 'static> TableModel<T>
Sourcepub fn new(columns: Vec<Column<T>>) -> Self
pub fn new(columns: Vec<Column<T>>) -> Self
Creates the native table with these columns (not yet in a window: it’s added the first time it’s shown). Create it once and update its rows in place.
Sourcepub fn set_columns(&self, columns: Vec<Column<T>>)
pub fn set_columns(&self, columns: Vec<Column<T>>)
Replaces the columns, keeping the same native table (a query
browser’s results change shape with every query). The sort is
cleared. Call set_rows after it when the rows
change too: nothing is drawn in between.
Sourcepub fn set_rows(&self, rows: Vec<T>)
pub fn set_rows(&self, rows: Vec<T>)
Replaces all rows (the current sort is applied). Clears the selection.
Sourcepub fn update_row(&self, index: usize, row: T)
pub fn update_row(&self, index: usize, row: T)
Replaces one row. Redraws only that row unless the table is sorted (then the order is recomputed; the selection is kept).
Sourcepub fn insert(&self, index: usize, row: T)
pub fn insert(&self, index: usize, row: T)
Inserts a row at a model index (the selection is kept).
Sourcepub fn append(&self, rows: Vec<T>)
pub fn append(&self, rows: Vec<T>)
Appends rows in one step, for live data (a log tail, a feed): when unsorted, the new rows are added to the end and AppKit only learns the new count (cost independent of the rows already there; the selection is kept). When sorted, the order is recomputed.
Sourcepub fn scroll_to_end(&self)
pub fn scroll_to_end(&self)
Scrolls so the last row is visible.
Sourcepub fn is_at_end(&self) -> bool
pub fn is_at_end(&self) -> bool
Whether the table is scrolled to its last row (within one row), e.g. to keep following new rows only while the user hasn’t scrolled up.
Sourcepub fn remove(&self, index: usize) -> Option<T>
pub fn remove(&self, index: usize) -> Option<T>
Removes a row (the selection is kept for the other rows).
Sourcepub fn move_rows(&self, rows: &[usize], before: Option<usize>) -> Vec<usize>
pub fn move_rows(&self, rows: &[usize], before: Option<usize>) -> Vec<usize>
Moves rows (model indices) to just above the row before (or to
the end), keeping their order, as a drop reported by
Table::reorderable asks. Returns their new model indices; they
end up selected.
Sourcepub fn focused_column(&self) -> Option<String>
pub fn focused_column(&self) -> Option<String>
The focused column’s id (see set_cell_focus).
Sourcepub fn set_focused_column(&self, column: Option<&str>)
pub fn set_focused_column(&self, column: Option<&str>)
Focuses a column by id (None: no column), scrolling it into view.
Doesn’t report an event.
Sourcepub fn selected_text(&self) -> String
pub fn selected_text(&self) -> String
The selected rows as tab-separated text (columns in their current order, one line per row, as ⌘C copies them).
Sourcepub fn copy_to(&self, pasteboard: &NSPasteboard) -> bool
pub fn copy_to(&self, pasteboard: &NSPasteboard) -> bool
Copies the selected rows to pasteboard (what ⌘C does with the
general pasteboard). False if nothing is selected.
Sourcepub fn paste_from(&self, pasteboard: &NSPasteboard) -> bool
pub fn paste_from(&self, pasteboard: &NSPasteboard) -> bool
Pastes pasteboard’s text (what ⌘V does with the general
pasteboard): goes to Table::on_paste if the table takes pastes.
Sourcepub fn row_at(&self, position: usize) -> Option<usize>
pub fn row_at(&self, position: usize) -> Option<usize>
The model index of the row shown at position (0 = top row as
currently sorted); None past the end or for a group header.
Sourcepub fn set_group_by(&self, key: Option<GroupKey<T>>)
pub fn set_group_by(&self, key: Option<GroupKey<T>>)
Groups the rows under headers by key (e.g. a date or a category):
groups appear in the order their first row has in the model, rows
keep the sort’s order within each group, and each group starts with
a header row showing the key (full width, not selectable, floating
while its rows scroll). None ungroups. Row indices in events stay
model indices.
Sourcepub fn groups(&self) -> Vec<String>
pub fn groups(&self) -> Vec<String>
The groups’ titles, in the order shown (empty when not grouped).
Sourcepub fn shown_rows(&self) -> usize
pub fn shown_rows(&self) -> usize
The number of rows shown, group headers included.
Sourcepub fn set_sort(&self, sort: Option<Sort>)
pub fn set_sort(&self, sort: Option<Sort>)
Sets the sort (shown in the header) and, with built-in sorting, applies it.
Sourcepub fn set_sorts_in_place(&self, on: bool)
pub fn set_sorts_in_place(&self, on: bool)
Built-in sorting (default on): header clicks reorder the rows here.
Turn it off to sort yourself on Table::on_sort (e.g. in a database)
and call TableModel::set_rows.
Sourcepub fn column_state(&self) -> Vec<ColumnState>
pub fn column_state(&self) -> Vec<ColumnState>
Columns in their current order, with widths.
Sourcepub fn set_column_state(&self, state: &[ColumnState])
pub fn set_column_state(&self, state: &[ColumnState])
Restores a saved arrangement (unknown ids are ignored).
Sourcepub fn scroll_view(&self) -> Retained<NSScrollView> ⓘ
pub fn scroll_view(&self) -> Retained<NSScrollView> ⓘ
The NSScrollView holding the table, for hosts that place it
themselves (no crate::attached window).
Sourcepub fn table_view(&self) -> Retained<NSTableView> ⓘ
pub fn table_view(&self) -> Retained<NSTableView> ⓘ
The underlying NSTableView (escape hatch).