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.
sortable orders by the stored column, so a type a driver stores as text
sorts by its spelling: a decimal column on SQLite, MySQL or Turso lists 10.00, 100, 9.50.
The ModelColumns derive leaves a type that is not
SORTABLE unsortable.
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());A cell also links to a url, shows a tooltip, cuts a long
value to a limit, offers a copyable button, shows an
icon before the value, and a placeholder for an empty
one:
use tablo_core::{Reads, TextColumn, lens};
TextColumn::new(lens!(User.email))
.url(|user: &User| Some(format!("mailto:{}", user.email)))
.reading(Reads::nothing())
.copyable();
TextColumn::new(lens!(User.bio)).limit(40);
TextColumn::new(lens!(User.phone)).placeholder("No phone");A closure over the row, a description, a url, a
tooltip or a money_by, may read any field, so a
resource that restricts a field refuses the column until
reading declares the ones they read.
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.
Sourcepub fn url(
self,
url: impl Fn(&M) -> Option<String> + Send + Sync + 'static,
) -> Self
pub fn url( self, url: impl Fn(&M) -> Option<String> + Send + Sync + 'static, ) -> Self
Link the value to url(row), or show it unlinked when that is None. The link takes a
relative URL or an http, https, mailto or tel one; any other scheme, such as
javascript:, leaves the value unlinked.
Sourcepub fn open_url_in_new_tab(self) -> Self
pub fn open_url_in_new_tab(self) -> Self
Open the url in a new tab.
Sourcepub fn tooltip(
self,
tooltip: impl Fn(&M) -> Option<String> + Send + Sync + 'static,
) -> Self
pub fn tooltip( self, tooltip: impl Fn(&M) -> Option<String> + Send + Sync + 'static, ) -> Self
Show tooltip(row) when the pointer rests on the value.
Sourcepub fn limit(self, chars: usize) -> Self
pub fn limit(self, chars: usize) -> Self
Show at most chars characters of the value, then an ellipsis; the whole value shows
when the pointer rests on it, unless a tooltip says otherwise. Search,
sort and export read the whole value.
Sourcepub fn copyable(self) -> Self
pub fn copyable(self) -> Self
Follow the value with a button copying it to the clipboard, which needs JavaScript.
Sourcepub fn placeholder(self, placeholder: impl Into<Text>) -> Self
pub fn placeholder(self, placeholder: impl Into<Text>) -> Self
Show placeholder for an empty value, in place of a dash. An export writes the empty
value.
Sourcepub fn icon(
self,
icon: impl Fn(&T) -> Option<IconData> + Send + Sync + 'static,
) -> Self
pub fn icon( self, icon: impl Fn(&T) -> Option<IconData> + Send + Sync + 'static, ) -> Self
Show icon(value) before the value, in its color, replacing a badge’s dot.
Sourcepub fn reading(self, reads: Reads<M>) -> Self
pub fn reading(self, reads: Reads<M>) -> Self
Declare the fields the closures over the row read, beside the column’s own: the
description, url, tooltip and
money_by.
Sourcepub fn weight(self, weight: FontWeight) -> Self
pub fn weight(self, weight: FontWeight) -> Self
Render the value in weight, such as a product’s name in FontWeight::Medium. A
badge keeps its own weight.
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.
Source§impl<M, T> TextColumn<M, T>
impl<M, T> TextColumn<M, T>
Sourcepub fn numeric(self, decimals: u8) -> Self
pub fn numeric(self, decimals: u8) -> Self
Spell the value as a number with decimals digits after the point and its thousands
grouped in the request’s locale, 12,345.60 in English and 12 345,60 in French, aligned
to the end with equal-width digits.
Trait Implementations§
Source§impl<M, T> Clone for TextColumn<M, T>
impl<M, T> Clone for TextColumn<M, T>
Source§impl<M, T> Column<M> for TextColumn<M, T>
impl<M, T> Column<M> for TextColumn<M, T>
Source§fn column_width(&self) -> ColumnWidth
fn column_width(&self) -> ColumnWidth
Source§fn toggle(&self) -> ColumnToggle
fn toggle(&self) -> ColumnToggle
Source§fn order_by(&self, descending: bool) -> Option<OrderByExpr>
fn order_by(&self, descending: bool) -> Option<OrderByExpr>
None when the header does not link to a
sort on it. A sortable column answers Some either way.