Skip to main content

TextColumn

Struct TextColumn 

Source
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,

Source

pub fn new(lens: Lens<M, T>) -> Self
where T: FormScalar + Send + Sync + 'static,

Bind a column to the field lens reads, which must be one field of the model.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn open_url_in_new_tab(self) -> Self

Open the url in a new tab.

Source

pub fn tooltip( self, tooltip: impl Fn(&M) -> Option<String> + Send + Sync + 'static, ) -> Self

Show tooltip(row) when the pointer rests on the value.

Source

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.

Source

pub fn copyable(self) -> Self

Follow the value with a button copying it to the clipboard, which needs JavaScript.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn align(self, alignment: Alignment) -> Self

Align the header and the cells.

Source

pub fn label(self, label: impl Into<Text>) -> Self

Replace the label the field’s name gives it.

Source

pub fn width(self, width: ColumnWidth) -> Self

Declare this column’s width.

Source

pub fn toggleable(self) -> Self

Let each reader hide this column from their list; it starts shown.

Source

pub fn hidden_by_default(self) -> Self

Let each reader show this column in their list; it starts hidden.

Source

pub fn sortable(self) -> Self

Make the header a sort link.

Source§

impl<M, T> TextColumn<M, T>
where M: Model, T: Numeric + 'static,

Source

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.

Source

pub fn money(self, currency: Currency) -> Self

Spell the value as an amount of currency in the request’s locale, $1,234.50 in English and 1 234,50 $ in French, aligned to the end with equal-width digits.

Source

pub fn money_by( self, currency: impl Fn(&M) -> Currency + Send + Sync + 'static, ) -> Self

Spell the value as an amount of the currency currency(row) names, such as an order’s own, aligned as money aligns it.

Source§

impl<M, T> TextColumn<M, T>
where M: Model + Send + Sync + 'static, T: Field<Inner = String> + Send + Sync + 'static,

Source

pub fn searchable(self) -> Self

Join the table’s search with a substring match on this string field.

Trait Implementations§

Source§

impl<M, T> Clone for TextColumn<M, T>

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<M, T> Column<M> for TextColumn<M, T>
where M: Model + Send + Sync + 'static, T: Send + Sync + 'static,

Source§

fn search_expr(&self, term: &str) -> Option<Expr<bool>>

A portable, escaped substring match.

Source§

fn name(&self) -> &str

The column’s identifier, distinct within its table.
Source§

fn label(&self) -> Text

The header text.
Source§

fn column_width(&self) -> ColumnWidth

The width the column claims.
Source§

fn toggle(&self) -> ColumnToggle

Whether each reader may hide or show the column in their list, and how it starts. A detail page shows every column.
Source§

fn reads(&self) -> Option<Reads<M>>

The fields of the row text, cell, entry, search_expr and order_by read, or None when the column does not say. Read more
Source§

fn text(&self, cx: &Cx, row: &M) -> String

The row’s value as plain text.
Source§

fn cell<'a>(&self, cx: &'a Cx, row: &M) -> BoxView<'a>

The row’s table cell.
Source§

fn alignment(&self) -> Alignment

Where the header and the cells align their content.
Source§

fn order_by(&self, descending: bool) -> Option<OrderByExpr>

The ordering a sort on this column applies, or None when the header does not link to a sort on it. A sortable column answers Some either way.
Source§

fn entry<'a>(&self, cx: &'a Cx, row: &M) -> BoxView<'a>

The record’s entry on a detail page: the label over the cell.
Source§

fn includes(&self) -> Includes<M>

The relations text, cell and entry read.
Source§

impl<M, T> Debug for TextColumn<M, T>

Source§

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

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

impl<M, T> IntoColumns<M> for TextColumn<M, T>
where Self: Column<M> + 'static,

Source§

impl<M, T> IntoDetail<M> for TextColumn<M, T>
where Self: Column<M> + 'static,

Auto Trait Implementations§

§

impl<M, T> !RefUnwindSafe for TextColumn<M, T>

§

impl<M, T> !UnwindSafe for TextColumn<M, T>

§

impl<M, T> Forget for TextColumn<M, T>

§

impl<M, T> Freeze for TextColumn<M, T>
where Lens<M, T>: Freeze, Arc<dyn Fn(&Cx, &M, &T) -> Text + Send + Sync>: Freeze, Arc<dyn Fn(&T) -> Option<Color> + Send + Sync>: Freeze, Option<Arc<dyn Fn(&M) -> String + Send + Sync>>: Freeze, Arc<dyn Fn(&T) -> Option<IconData> + Send + Sync>: Freeze, Option<Arc<dyn Fn(&M) -> Option<String> + Send + Sync>>: Freeze, Option<Reads<M>>: Freeze,

§

impl<M, T> Send for TextColumn<M, T>
where Lens<M, T>: Send, Arc<dyn Fn(&Cx, &M, &T) -> Text + Send + Sync>: Send, Arc<dyn Fn(&T) -> Option<Color> + Send + Sync>: Send, Option<Arc<dyn Fn(&M) -> String + Send + Sync>>: Send, Arc<dyn Fn(&T) -> Option<IconData> + Send + Sync>: Send, Option<Arc<dyn Fn(&M) -> Option<String> + Send + Sync>>: Send, Option<Reads<M>>: Send,

§

impl<M, T> Sync for TextColumn<M, T>
where Lens<M, T>: Sync, Arc<dyn Fn(&Cx, &M, &T) -> Text + Send + Sync>: Sync, Arc<dyn Fn(&T) -> Option<Color> + Send + Sync>: Sync, Option<Arc<dyn Fn(&M) -> String + Send + Sync>>: Sync, Arc<dyn Fn(&T) -> Option<IconData> + Send + Sync>: Sync, Option<Arc<dyn Fn(&M) -> Option<String> + Send + Sync>>: Sync, Option<Reads<M>>: Sync,

§

impl<M, T> Unpin for TextColumn<M, T>
where Lens<M, T>: Unpin, Arc<dyn Fn(&Cx, &M, &T) -> Text + Send + Sync>: Unpin, Arc<dyn Fn(&T) -> Option<Color> + Send + Sync>: Unpin, Option<Arc<dyn Fn(&M) -> String + Send + Sync>>: Unpin, Arc<dyn Fn(&T) -> Option<IconData> + Send + Sync>: Unpin, Option<Arc<dyn Fn(&M) -> Option<String> + Send + Sync>>: Unpin, Option<Reads<M>>: Unpin,

§

impl<M, T> UnsafeUnpin for TextColumn<M, T>

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

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

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