Skip to main content

DataGrid

Struct DataGrid 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn cell_style( self, style: impl Fn(&Row, usize) -> GridCellStyle + 'static, ) -> Self

Decides how each cell looks, from its row and its column.

Source

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.

Source

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.

Source

pub fn detail_height(self, height: f32) -> Self

The height of a row’s details in logical pixels. 240 by default.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn page_size(self, rows: usize) -> Self

Shows the rows a page at a time, with a pager at the bottom.

Source

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.

Source

pub fn vertical_lines(self, show: bool) -> Self

Draws a line between columns.

Source

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.

Source

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.

Source

pub fn selection_mode(self, mode: SelectionMode) -> Self

Sets how rows can be selected (single by default).

Source

pub fn selection(self, selection: Binding<BTreeSet<usize>>) -> Self

Where the selected row indices live (otherwise the grid keeps them).

Source

pub fn key_column(self, column: usize) -> Self

The column that identifies a record, for selected_keys and the names of GridRowActions.

Source

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.

Source

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.

Source

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.

Source

pub fn row_action(self, action: GridRowAction) -> Self

Adds a button at the end of every row.

Source

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.

Source

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.

Source

pub fn sort_by(self, column: usize, direction: SortDirection) -> Self

Initial sort; call again to add more sort columns.

Source

pub fn group_by(self, column: usize) -> Self

Initial grouping; call again for nested groups.

Source

pub fn filter_row(self, show: bool) -> Self

Shows or hides the filter row under the header.

Source

pub fn search_panel(self, show: bool) -> Self

Shows or hides the search box in the toolbar.

Source

pub fn toolbar(self, show: bool) -> Self

The toolbar with search, grouping, column chooser and export.

Source

pub fn footer(self, show: bool) -> Self

The footer with column totals.

Source

pub fn height(self, height: f32) -> Self

A fixed height; otherwise the grid fills the space its parent gives it.

Source

pub fn row_height(self, height: f32) -> Self

Sets the row height in logical pixels (36 by default, at least 24).

Source

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.

Source

pub fn even_row(self, color: Color) -> Self

Paints the second, fourth and so on rows in this color, in place of Self::striped.

Source

pub fn odd_row(self, color: Color) -> Self

Paints the first, third and so on rows in this color.

Source

pub fn horizontal_lines(self, show: bool) -> Self

Whether a line separates the rows. On by default.

Source

pub fn on_export(self, handler: impl Fn(String) + 'static) -> Self

Shows an Export button; handler receives the matching rows as CSV.

Source

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§

Source§

impl Debug for DataGrid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl View for DataGrid

Source§

fn build(&self, cx: &mut BuildCx<'_>) -> NodeId

Creates this view’s node for the current build.
Source§

fn type_name(&self) -> &'static str

The name the diagnostics panel shows this view’s cost under.

Auto Trait Implementations§

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
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<V> ViewExt for V
where V: View,

Source§

fn padding(self, padding: impl Into<Insets>) -> Styled<Self>

Adds padding inside the box, in logical pixels.
Source§

fn background(self, fill: impl Into<Fill>) -> Styled<Self>

Paints a background behind the content.
Source§

fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>

Fixes the width and/or height in logical pixels; None keeps the content size.
Source§

fn width(self, width: f32) -> Styled<Self>

Fixes the width in logical pixels.
Source§

fn height(self, height: f32) -> Styled<Self>

Fixes the height in logical pixels.
Source§

fn grow(self, grow: f32) -> Styled<Self>

Takes a share of the free space in the parent stack.
Source§

fn stretch(self) -> Styled<Self>

Stretches across the parent stack’s cross axis.
Source§

fn centered(self) -> Styled<Self>

Centers the content inside the box.
Source§

fn tooltip(self, text: impl Into<String>) -> Tooltip<Self>

Shows text above the view while the pointer is over it; see Tooltip.
Source§

fn opacity(self, opacity: f32) -> Faded<Self>

Draws the view and everything in it at this opacity, from 0.0 to 1.0, easing to it when it changes. Layout and input stay as they are; see Faded.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more