pub struct TextColumn<M, T> { /* private fields */ }Expand description
A column of one field, rendered as text and bound through a Lens for sorting and search.
tablo_core::TextColumn::new(tablo_core::lens!(User.name))
.searchable()
.sortable();
tablo_core::TextColumn::new(tablo_core::lens!(User.age))
.sortable()
.format(|age| format!("{age} years"));The cell is the value’s FormScalar::to_label, an Options enum’s label
or any other type’s form spelling, unless format says otherwise. Only a
string field is searchable.
A column presents its value as a badge, in a color, with a
muted description line under it, or as a right-aligned
numeric or money amount:
use tablo_core::{Currency, TextColumn, lens};
TextColumn::new(lens!(Order.number)).description(|order: &Order| order.customer.clone());
TextColumn::new(lens!(Order.status)).badge();
TextColumn::new(lens!(Order.total_cents)).money(Currency::USD.minor_units());Implementations§
Source§impl<M, T> TextColumn<M, T>where
M: Model,
impl<M, T> TextColumn<M, T>where
M: Model,
Sourcepub fn new(lens: Lens<M, T>) -> Self
pub fn new(lens: Lens<M, T>) -> Self
Bind a column to the field lens reads, which must be one field of the model.
Sourcepub fn format<L: Into<Text>>(
self,
format: impl Fn(&T) -> L + Send + Sync + 'static,
) -> Self
pub fn format<L: Into<Text>>( self, format: impl Fn(&T) -> L + Send + Sync + 'static, ) -> Self
Render the field’s value through format: a String, or a Text the request’s locale
spells.
Sourcepub fn badge(self) -> Self
pub fn badge(self) -> Self
Show the value as a badge, with a dot in its color: an Options enum’s
#[option(color = "…")], or the color declared here.
Sourcepub fn color(
self,
color: impl Fn(&T) -> Option<Color> + Send + Sync + 'static,
) -> Self
pub fn color( self, color: impl Fn(&T) -> Option<Color> + Send + Sync + 'static, ) -> Self
Color the value: its badge’s dot, or its text when it is no badge.
Sourcepub fn description(
self,
description: impl Fn(&M) -> String + Send + Sync + 'static,
) -> Self
pub fn description( self, description: impl Fn(&M) -> String + Send + Sync + 'static, ) -> Self
Show description(row) as a muted line under the value, such as a customer’s email under
their name. Search, sort and export read the value alone.
The description may read any field, so a resource that
restricts a field refuses the column until
reading declares the ones it reads.
Sourcepub fn reading(self, reads: Reads<M>) -> Self
pub fn reading(self, reads: Reads<M>) -> Self
Declare the fields the description reads, beside the column’s own.
Sourcepub fn label(self, label: impl Into<Text>) -> Self
pub fn label(self, label: impl Into<Text>) -> Self
Replace the label the field’s name gives it.
Sourcepub fn width(self, width: ColumnWidth) -> Self
pub fn width(self, width: ColumnWidth) -> Self
Declare this column’s width.
Sourcepub fn toggleable(self) -> Self
pub fn toggleable(self) -> Self
Let each reader hide this column from their list; it starts shown.
Let each reader show this column in their list; it starts hidden.