pub struct ComputedColumn<M> { /* private fields */ }Expand description
A display-only column rendering any text from the row, with no query predicate.
tablo_core::ComputedColumn::new("Words", |_, p: &Post| {
p.body.split_whitespace().count().to_string()
});A closure that reads a relation declares it with include_unscoped,
so the page loads it. One relation’s record or count is a
RelationColumn or a CountColumn, which
declare their own and show only what the related resource shows the user.
It maps to no column, so it neither searches nor sorts.
A badge shows the text in an outline badge, with a dot in the
color the row gives it:
use tablo_core::{Color, ComputedColumn, Reads, lens};
ComputedColumn::new("Size", |_, o: &Order| {
if o.total_cents > 100_00 {
"Large"
} else {
"Small"
}
.to_string()
})
.badge()
.color(|_, o: &Order| (o.total_cents > 100_00).then_some(Color::Success))
.reading(Reads::of(lens!(Order.total_cents)));Implementations§
Source§impl<M> ComputedColumn<M>where
M: Model,
impl<M> ComputedColumn<M>where
M: Model,
Sourcepub fn new(
label: impl Into<Text>,
project: impl Fn(&Cx, &M) -> String + Send + Sync + 'static,
) -> ComputedColumn<M>
pub fn new( label: impl Into<Text>, project: impl Fn(&Cx, &M) -> String + Send + Sync + 'static, ) -> ComputedColumn<M>
Declare a column headed label rendering project(cx, row), named after the label: its
plain text in lowercase, or its message’s id.
Sourcepub fn badge(self) -> ComputedColumn<M>
pub fn badge(self) -> ComputedColumn<M>
Show the text as a badge, with a dot in its color.
Sourcepub fn color(
self,
color: impl Fn(&Cx, &M) -> Option<Color> + Send + Sync + 'static,
) -> ComputedColumn<M>
pub fn color( self, color: impl Fn(&Cx, &M) -> Option<Color> + Send + Sync + 'static, ) -> ComputedColumn<M>
Color the text by color(cx, row): its badge’s dot, or the text itself when it is no
badge. reading declares what it reads, beside the projection.
Sourcepub fn include_unscoped<T>(
self,
relation: impl Into<Include<M, T>>,
) -> ComputedColumn<M>
pub fn include_unscoped<T>( self, relation: impl Into<Include<M, T>>, ) -> ComputedColumn<M>
Declare a relation the projection reads, so the table loads it. The projection reads
whatever the include loads, under no resource’s query or policy, as an
unscoped relation column does: another tenant’s record,
or one the user may not view, reaches it.
Sourcepub fn reading(self, reads: Reads<M>) -> ComputedColumn<M>
pub fn reading(self, reads: Reads<M>) -> ComputedColumn<M>
Declare the fields the projection and its color read, which a resource
restricting a field with field_access needs: the
column shows only to a user who may view every one.
Sourcepub fn width(self, width: ColumnWidth) -> ComputedColumn<M>
pub fn width(self, width: ColumnWidth) -> ComputedColumn<M>
Declare this column’s width.
Sourcepub fn align(self, alignment: Alignment) -> ComputedColumn<M>
pub fn align(self, alignment: Alignment) -> ComputedColumn<M>
Align the header and the cells.
Sourcepub fn toggleable(self) -> ComputedColumn<M>
pub fn toggleable(self) -> ComputedColumn<M>
Let each reader hide this column from their list; it starts shown.
Let each reader show this column in their list; it starts hidden.
Trait Implementations§
Source§impl<M> Clone for ComputedColumn<M>
impl<M> Clone for ComputedColumn<M>
Source§fn clone(&self) -> ComputedColumn<M>
fn clone(&self) -> ComputedColumn<M>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more