Skip to main content

DataTable

Struct DataTable 

Source
pub struct DataTable {
Show 23 fields pub key: Option<KeyRef>, pub columns: Vec<DataColumn>, pub sort_column_index: Option<usize>, pub sort_ascending: bool, pub sort_icon_builder: Option<DataTableSortIconBuilder>, pub on_select_all: Option<ValueChanged<Option<bool>>>, pub decoration: Option<DecorationRef>, pub data_row_color: Option<WidgetStatePropertyRef<Option<Color>>>, pub data_row_min_height: Option<f64>, pub data_row_max_height: Option<f64>, pub data_text_style: Option<TextStyle>, pub heading_row_color: Option<WidgetStatePropertyRef<Option<Color>>>, pub heading_row_height: Option<f64>, pub heading_text_style: Option<TextStyle>, pub horizontal_margin: Option<f64>, pub column_spacing: Option<f64>, pub show_checkbox_column: bool, pub rows: Vec<DataRow>, pub divider_thickness: Option<f64>, pub show_bottom_border: bool, pub checkbox_horizontal_margin: Option<f64>, pub border: Option<TableBorder>, pub clip_behavior: Clip, /* private fields */
}
Expand description

A Material Design data table.

Displaying data in a table is expected to be a common operation. For example, a list of users, with each user having a name, an age, and so on.

If the on_select_changed of any row is set, a checkbox column is shown first, and a DataRow with a null on_select_changed is disabled.

The DataTable widget does not scroll on its own: if the table might be too large for its parent, wrap it in a scrollable. A DataTable must have a Material ancestor if any of its columns or rows are interactive.

The width of each column is determined by the algorithm in Table: by default, a column that is the only non-numeric column gets an IntrinsicColumnWidth with a flex of 1, and every other column an IntrinsicColumnWidth without one, unless the DataColumn gives a column_width.

See also:

  • PaginatedDataTable, which shows part of the data in a data table and provides controls for paging through the remainder of the data.
  • TableRowInkWell, a widget used to provide ink to a table row.

Fields§

§key: Option<KeyRef>§columns: Vec<DataColumn>

The configuration and labels for the columns in the table.

§sort_column_index: Option<usize>

The current primary sort key’s column.

If non-null, indicates that the indicated column is the column by which the data is sorted. The number must correspond to the index of the relevant column in [columns].

Setting this will cause the relevant column to have a sort indicator displayed.

When this is null, it implies that the table’s sort order does not correspond to any of the columns.

The direction of the sort is specified using sort_ascending.

§sort_ascending: bool

Whether the column mentioned in sort_column_index, if any, is sorted in ascending order.

If true, the order is ascending (meaning the rows with the smallest values for the current sort column are first in the table).

If false, the order is descending (meaning the rows with the smallest values for the current sort column are last in the table).

Ascending order is represented by an upwards-facing arrow.

§sort_icon_builder: Option<DataTableSortIconBuilder>

Overrides the default sort indicator (an arrow) shown in a sortable column’s heading.

If null, the default arrow is used. Otherwise it is called with whether the column is sorted and whether it is sorted ascending.

§on_select_all: Option<ValueChanged<Option<bool>>>

Invoked when the user selects or unselects every row, using the checkbox in the heading row.

If this is null, then the DataRow::on_select_changed callback of every row in the table is invoked appropriately instead.

To control whether a particular row is selectable or not, see DataRow::on_select_changed. This callback is only relevant if any row is selectable.

§decoration: Option<DecorationRef>

The background and border decoration for the table.

§data_row_color: Option<WidgetStatePropertyRef<Option<Color>>>

The background color for the data rows.

The effective background color can be made to depend on the WidgetState state, i.e. if the row is selected, pressed, hovered, focused, disabled or enabled. The color is painted as an overlay to the row. To make sure that the row’s InkWell is visible (when pressed, hovered and focused), it is recommended to use a translucent color.

If DataRow::color is non-null for a row, that color is used for that row instead.

§data_row_min_height: Option<f64>

The minimum height of each row (excluding the row that contains column headings).

This value is optional and defaults to K_MIN_INTERACTIVE_DIMENSION if not specified.

§data_row_max_height: Option<f64>

The maximum height of each row (excluding the row that contains column headings).

This value is optional and defaults to K_MIN_INTERACTIVE_DIMENSION if not specified.

§data_text_style: Option<TextStyle>

The text style for data rows.

By default, the text style is TextTheme::body_medium.

§heading_row_color: Option<WidgetStatePropertyRef<Option<Color>>>

The background color for the heading row.

The effective background color can be made to depend on the WidgetState state, i.e. if the row is pressed, hovered, focused when sorted. The color is painted as an overlay to the row.

§heading_row_height: Option<f64>

The height of the heading row.

This value is optional and defaults to 56.0 if not specified.

§heading_text_style: Option<TextStyle>

The text style for the heading row.

By default, the text style is TextTheme::title_small.

§horizontal_margin: Option<f64>

The horizontal margin between the edges of the table and the content in the first and last cells of each row.

When a checkbox is displayed, it is also the margin between the checkbox the content in the first data column.

This value defaults to 24.0 to adhere to the Material Design specifications.

If checkbox_horizontal_margin is null, then horizontal_margin is also the margin between the edge of the table and the checkbox, as well as the margin between the checkbox and the content in the first data column.

§column_spacing: Option<f64>

The horizontal margin between the contents of each data column.

This value defaults to 56.0 to adhere to the Material Design specifications.

§show_checkbox_column: bool

Whether the widget should display checkboxes for selectable rows.

If true, a Checkbox will be placed at the beginning of each row that is selectable. However, if DataRow::on_select_changed is not set for any row, checkboxes will not be placed, even if this value is true.

If false, all rows will not display a Checkbox.

§rows: Vec<DataRow>

The data to show in each row (excluding the row that contains the column headings).

The list may be empty.

§divider_thickness: Option<f64>

The thickness of the divider between rows.

This value is optional and defaults to 1.0 if not specified.

§show_bottom_border: bool

Whether a border at the bottom of the table is displayed.

By default, a border is not shown at the bottom to allow for a border around the table defined by decoration.

§checkbox_horizontal_margin: Option<f64>

Horizontal margin around the checkbox, if it is displayed.

If null, then horizontal_margin is used as the margin between the edge of the table and the checkbox, as well as the margin between the checkbox and the content in the first data column. This value defaults to 24.0.

§border: Option<TableBorder>

The style to use when painting the boundary and interior divisions of the table.

§clip_behavior: Clip

{@macro flutter.material.Material.clipBehavior}

This can be used to clip the content within the border of the DataTable.

Defaults to Clip::None.

Implementations§

Source§

impl DataTable

Source

pub fn new(columns: Vec<DataColumn>, rows: Vec<DataRow>) -> DataTable

Creates a widget describing a data table; Dart’s optional named arguments are the setters.

The columns argument must be a list of as many DataColumn objects as the table is to have columns, ignoring the leading checkbox column which may be omitted. The rows argument must be a list of DataRow objects to be shown, each with a DataRow::cells list of the same length as columns.

Source

pub fn key(self, key: KeyRef) -> DataTable

Dart DataTable(key:).

Source

pub fn sort_column_index(self, sort_column_index: usize) -> DataTable

Dart DataTable(sortColumnIndex:).

Source

pub fn sort_ascending(self, sort_ascending: bool) -> DataTable

Dart DataTable(sortAscending:).

Source

pub fn sort_icon_builder( self, sort_icon_builder: impl Fn(&mut App, BuildContext, bool, bool) -> WidgetRef + 'static, ) -> DataTable

Dart DataTable(sortIconBuilder:).

Source

pub fn on_select_all( self, on_select_all: impl Fn(&mut App, Option<bool>) + 'static, ) -> DataTable

Dart DataTable(onSelectAll:).

Source

pub fn decoration(self, decoration: impl Into<DecorationRef>) -> DataTable

Dart DataTable(decoration:).

Source

pub fn data_row_color( self, data_row_color: WidgetStatePropertyRef<Option<Color>>, ) -> DataTable

Dart DataTable(dataRowColor:).

Source

pub fn data_row_height(self, data_row_height: f64) -> DataTable

👎Deprecated:

Migrate to use data_row_min_height and data_row_max_height instead. This feature was deprecated after v3.7.0-5.0.pre.

Dart’s deprecated DataTable(dataRowHeight:): it sets data_row_min_height and data_row_max_height to one value.

Dart asserts that the argument is not given with either of them; a fluent chain has no one call to compare, so a later setter replaces what an earlier one wrote.

Source

pub fn data_row_min_height(self, data_row_min_height: f64) -> DataTable

Dart DataTable(dataRowMinHeight:).

Source

pub fn data_row_max_height(self, data_row_max_height: f64) -> DataTable

Dart DataTable(dataRowMaxHeight:).

Source

pub fn data_text_style(self, data_text_style: TextStyle) -> DataTable

Dart DataTable(dataTextStyle:).

Source

pub fn heading_row_color( self, heading_row_color: WidgetStatePropertyRef<Option<Color>>, ) -> DataTable

Dart DataTable(headingRowColor:).

Source

pub fn heading_row_height(self, heading_row_height: f64) -> DataTable

Dart DataTable(headingRowHeight:).

Source

pub fn heading_text_style(self, heading_text_style: TextStyle) -> DataTable

Dart DataTable(headingTextStyle:).

Source

pub fn horizontal_margin(self, horizontal_margin: f64) -> DataTable

Dart DataTable(horizontalMargin:).

Source

pub fn column_spacing(self, column_spacing: f64) -> DataTable

Dart DataTable(columnSpacing:).

Source

pub fn show_checkbox_column(self, show_checkbox_column: bool) -> DataTable

Dart DataTable(showCheckboxColumn:).

Source

pub fn show_bottom_border(self, show_bottom_border: bool) -> DataTable

Dart DataTable(showBottomBorder:).

Source

pub fn divider_thickness(self, divider_thickness: f64) -> DataTable

Dart DataTable(dividerThickness:).

Source

pub fn checkbox_horizontal_margin( self, checkbox_horizontal_margin: f64, ) -> DataTable

Dart DataTable(checkboxHorizontalMargin:).

Source

pub fn border(self, border: TableBorder) -> DataTable

Dart DataTable(border:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> DataTable

Dart DataTable(clipBehavior:).

Source

pub fn data_row_height_value(&self) -> Option<f64>

👎Deprecated:

Migrate to use data_row_min_height and data_row_max_height instead. This feature was deprecated after v3.7.0-5.0.pre.

Dart’s deprecated dataRowHeight getter: the row height, if the minimum and the maximum are the same.

Trait Implementations§

Source§

impl Clone for DataTable

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataTable

Source§

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

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

impl StatelessWidget for DataTable

Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_check_constructor(&self)

Dart’s constructor asserts that relate two or more arguments. Read more
Source§

fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef

Describes the part of the user interface represented by this widget. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Dart’s this is PreferredSizeWidget: a widget that implements PreferredSizeWidget answers with itself, which is what a parent asking an erased child for its preferred size reads.

Auto Trait Implementations§

§

impl !RefUnwindSafe for DataTable

§

impl !Send for DataTable

§

impl !Sync for DataTable

§

impl !UnwindSafe for DataTable

§

impl Forget for DataTable

§

impl Freeze for DataTable
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const u8 is !null: Freeze, PhantomData<DataColumn>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, bool, bool) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, bool, bool) -> Rc<dyn Widget>>>: Freeze, *const RcInner<dyn Fn(&mut App, Option<bool>)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, Option<bool>)>>: Freeze, *const RcInner<dyn Decoration> is !null: Freeze, PhantomData<RcInner<dyn Decoration>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: Freeze, &'static dyn ColorExtension: Freeze, *const RcInner<dyn ColorExtension> is !null: Freeze, PhantomData<RcInner<dyn ColorExtension>>: Freeze, PhantomData<u8>: Freeze, PhantomData<String>: Freeze, *const RcInner<Paint> is !null: Freeze, PhantomData<RcInner<Paint>>: Freeze, PhantomData<Shadow>: Freeze, PhantomData<FontFeature>: Freeze, PhantomData<FontVariation>: Freeze, PhantomData<DataRow>: Freeze,

§

impl Move for DataTable

§

impl Unpin for DataTable
where Rc<dyn Key>: Unpin, *const u8 is !null: Unpin, Rc<dyn Widget>: Unpin, Rc<dyn TableColumnWidth>: Unpin, Rc<dyn Fn(&mut App, i32, bool)>: Unpin, Rc<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>: Unpin, Rc<dyn Fn(&mut App, AnyElement, bool, bool) -> Rc<dyn Widget>>: Unpin, Rc<dyn Fn(&mut App, Option<bool>)>: Unpin, Rc<dyn Decoration>: Unpin, Rc<dyn WidgetStateProperty<Option<Color>>>: Unpin, &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin, Rc<Paint>: Unpin, Rc<dyn LocalKey>: Unpin, Rc<dyn Fn(&mut App)>: Unpin, NonZero<u32>: Unpin, *const (): Unpin, Rc<dyn Fn(&mut App, bool)>: Unpin, Rc<dyn Fn(&mut App, TapDownDetails)>: Unpin,

§

impl UnsafeUnpin for DataTable

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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<W> IntoWidget<StatelessKind> for W
where W: StatelessWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>