pub struct DataGrid { /* private fields */ }Expand description
A virtualized data grid in the spirit of enterprise grids: sorting by one or
several columns, a filter row with operators and filters by value, a search panel,
grouping by dragging columns to the group panel, group summaries, footer totals,
columns to resize, reorder, pin and hide, a menu on each column, single or multiple
selection, keyboard navigation, in-place editing, cell templates, CSV export, pages,
saved scenarios, and rows that stay on a server (DataGrid::remote). Only the
visible rows are built, so 100,000+ rows stay smooth.
use ravenrs_widgets::{DataGrid, GridColumn, GridData, SortDirection, Summary, Ui};
let data = GridData::new(vec![
vec!["Acme".into(), 1200.0.into()],
vec!["Globex".into(), 860.5.into()],
]);
let grid = DataGrid::new(
data,
[GridColumn::text("Customer"), GridColumn::currency("MRR", "$", 2).summary(Summary::Sum)],
)
.sort_by(1, SortDirection::Descending)
.height(320.0);
let mut ui = Ui::new(grid, ravenrs_style::Theme::raven_dark());
ui.update();Implementations§
Source§impl DataGrid
impl DataGrid
Sourcepub fn empty_text(self, text: impl Into<String>) -> Self
pub fn empty_text(self, text: impl Into<String>) -> Self
What it says when there is no data at all, as opposed to filters leaving nothing.
Sourcepub fn new(
data: GridData,
columns: impl IntoIterator<Item = GridColumn>,
) -> Self
pub fn new( data: GridData, columns: impl IntoIterator<Item = GridColumn>, ) -> Self
A grid over data with these columns; single selection, filter row, toolbar and footer on.
Sourcepub fn name_column(self, column: usize) -> Self
pub fn name_column(self, column: usize) -> Self
The column whose cell names a row for screen readers, in the buttons of
row_action. The key column, or else the first, by default.
Sourcepub fn cell_style(
self,
style: impl Fn(&Row, usize) -> GridCellStyle + 'static,
) -> Self
pub fn cell_style( self, style: impl Fn(&Row, usize) -> GridCellStyle + 'static, ) -> Self
Decides how each cell looks, from its row and its column.
Sourcepub fn filter_builder(self, show: bool) -> Self
pub fn filter_builder(self, show: bool) -> Self
Shows a Filter button in the toolbar that opens a FilterBuilder
over the columns. What it writes is an expression, kept with the filters of
the filter row, so it goes in saved scenarios and comes out with Clear.
Sourcepub fn row_detail(
self,
detail: impl Fn(&Row, usize) -> AnyView + 'static,
) -> Self
pub fn row_detail( self, detail: impl Fn(&Row, usize) -> AnyView + 'static, ) -> Self
Gives every row details of its own, opened by an arrow at its start or with the Right key: a nested list, a form, a chart. The view is built only while it is open, with the row and its index in the data.
Sourcepub fn detail_height(self, height: f32) -> Self
pub fn detail_height(self, height: f32) -> Self
The height of a row’s details in logical pixels. 240 by default.
Sourcepub fn expanded_rows(self, rows: Binding<BTreeSet<usize>>) -> Self
pub fn expanded_rows(self, rows: Binding<BTreeSet<usize>>) -> Self
The rows with details open, by index in the data, to keep or to set from outside.
Sourcepub fn on_export_file(
self,
handler: impl Fn(GridExportFormat, GridTable) + 'static,
) -> Self
pub fn on_export_file( self, handler: impl Fn(GridExportFormat, GridTable) + 'static, ) -> Self
Shows an Export menu with Excel, PDF and CSV; handler receives the format and the rows
that match, as shown. ravenrs-grid-export turns these into a file.
Sourcepub fn export_title(self, title: impl Into<String>) -> Self
pub fn export_title(self, title: impl Into<String>) -> Self
The title of the files the Export menu makes. The grid’s name by default.
Sourcepub fn remote(
rows: RemoteRows,
columns: impl IntoIterator<Item = GridColumn>,
) -> Self
pub fn remote( rows: RemoteRows, columns: impl IntoIterator<Item = GridColumn>, ) -> Self
A grid over rows that stay on a server. It asks for what is on the screen, keeps
a limited number of rows, and sorting, filtering and searching are up to the
loader. It scrolls on as rows arrive, or in pages with
page_size; grouping needs the rows at hand, so it is off.
Sourcepub fn page_size(self, rows: usize) -> Self
pub fn page_size(self, rows: usize) -> Self
Shows the rows a page at a time, with a pager at the bottom.
Sourcepub fn group_panel(self, show: bool) -> Self
pub fn group_panel(self, show: bool) -> Self
Shows or hides the space where columns are dropped to group by them. It shows along with the toolbar, unless this says otherwise.
Sourcepub fn vertical_lines(self, show: bool) -> Self
pub fn vertical_lines(self, show: bool) -> Self
Draws a line between columns.
Sourcepub fn layout(self, layout: Binding<GridLayout>) -> Self
pub fn layout(self, layout: Binding<GridLayout>) -> Self
Where its arrangement lives: read when it changes, and written when someone moves something. Keep this to bring it back as it was.
Sourcepub fn scenarios(self, scenarios: Binding<Vec<GridScenario>>) -> Self
pub fn scenarios(self, scenarios: Binding<Vec<GridScenario>>) -> Self
Offers saving its arrangement under a name and coming back to it. Keep the list
with GridScenario::list_to_json.
Sourcepub fn selection_mode(self, mode: SelectionMode) -> Self
pub fn selection_mode(self, mode: SelectionMode) -> Self
Sets how rows can be selected (single by default).
Sourcepub fn selection(self, selection: Binding<BTreeSet<usize>>) -> Self
pub fn selection(self, selection: Binding<BTreeSet<usize>>) -> Self
Where the selected row indices live (otherwise the grid keeps them).
Sourcepub fn key_column(self, column: usize) -> Self
pub fn key_column(self, column: usize) -> Self
The column that identifies a record, for selected_keys
and the names of GridRowActions.
Sourcepub fn selected_keys(self, keys: Binding<BTreeSet<String>>) -> Self
pub fn selected_keys(self, keys: Binding<BTreeSet<String>>) -> Self
Where the keys of the selected rows live, with
key_column. Unlike row indices, keys still mean the same
records after the data is replaced.
Sourcepub fn on_row_open(self, handler: impl Fn(&Row) + 'static) -> Self
pub fn on_row_open(self, handler: impl Fn(&Row) + 'static) -> Self
Double-click or Enter on a row, with the row’s values. Works the same over rows at hand and rows on a server.
Sourcepub fn on_cell_edit(
self,
handler: impl Fn(&CellEdit) -> Result<(), String> + 'static,
) -> Self
pub fn on_cell_edit( self, handler: impl Fn(&CellEdit) -> Result<(), String> + 'static, ) -> Self
Sees each edit before it is kept. An error stays on show, in the toolbar, and the
cell stays open. With it, columns marked editable can
be edited with a double-click over rows on a server too: the handler saves them.
Sourcepub fn row_action(self, action: GridRowAction) -> Self
pub fn row_action(self, action: GridRowAction) -> Self
Adds a button at the end of every row.
Sourcepub fn on_add_row(self, handler: impl Fn() + 'static) -> Self
pub fn on_add_row(self, handler: impl Fn() + 'static) -> Self
Shows an Add button in the toolbar. The handler adds the row, or opens a form to.
Sourcepub fn on_delete_rows(self, handler: impl Fn(Vec<usize>) + 'static) -> Self
pub fn on_delete_rows(self, handler: impl Fn(Vec<usize>) + 'static) -> Self
Lets the Delete key and a toolbar button remove the selected rows. The handler receives them, and it decides: it may ask first.
Sourcepub fn sort_by(self, column: usize, direction: SortDirection) -> Self
pub fn sort_by(self, column: usize, direction: SortDirection) -> Self
Initial sort; call again to add more sort columns.
Sourcepub fn filter_row(self, show: bool) -> Self
pub fn filter_row(self, show: bool) -> Self
Shows or hides the filter row under the header.
Sourcepub fn search_panel(self, show: bool) -> Self
pub fn search_panel(self, show: bool) -> Self
Shows or hides the search box in the toolbar.
Sourcepub fn toolbar(self, show: bool) -> Self
pub fn toolbar(self, show: bool) -> Self
The toolbar with search, grouping, column chooser and export.
The footer with column totals.
Sourcepub fn height(self, height: f32) -> Self
pub fn height(self, height: f32) -> Self
A fixed height; otherwise the grid fills the space its parent gives it.
Sourcepub fn row_height(self, height: f32) -> Self
pub fn row_height(self, height: f32) -> Self
Sets the row height in logical pixels (36 by default, at least 24).
Sourcepub fn striped(self, striped: bool) -> Self
pub fn striped(self, striped: bool) -> Self
Shades every other row with a tint of the theme’s control color, which leaves the accent to the selection. Counting starts again after each group row.
Sourcepub fn even_row(self, color: Color) -> Self
pub fn even_row(self, color: Color) -> Self
Paints the second, fourth and so on rows in this color, in place of Self::striped.
Sourcepub fn odd_row(self, color: Color) -> Self
pub fn odd_row(self, color: Color) -> Self
Paints the first, third and so on rows in this color.
Sourcepub fn horizontal_lines(self, show: bool) -> Self
pub fn horizontal_lines(self, show: bool) -> Self
Whether a line separates the rows. On by default.
Sourcepub fn on_export(self, handler: impl Fn(String) + 'static) -> Self
pub fn on_export(self, handler: impl Fn(String) + 'static) -> Self
Shows an Export button; handler receives the matching rows as CSV.
Sourcepub fn on_row_activate(self, handler: impl Fn(usize) + 'static) -> Self
pub fn on_row_activate(self, handler: impl Fn(usize) + 'static) -> Self
Double-click or Enter on a row whose cell is not editable.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DataGrid
impl !Send for DataGrid
impl !Sync for DataGrid
impl !UnwindSafe for DataGrid
impl Freeze for DataGrid
impl Unpin for DataGrid
impl UnsafeUnpin for DataGrid
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
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
None keeps the content size.