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(&M) -> String + Send + Sync + 'static,
) -> Self
pub fn new( label: impl Into<Text>, project: impl Fn(&M) -> String + Send + Sync + 'static, ) -> Self
Declare a column headed label rendering project(row), named after the label: its
plain text in lowercase, or its message’s id.
Sourcepub fn color(
self,
color: impl Fn(&M) -> Option<Color> + Send + Sync + 'static,
) -> Self
pub fn color( self, color: impl Fn(&M) -> Option<Color> + Send + Sync + 'static, ) -> Self
Color the text by color(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>>) -> Self
pub fn include_unscoped<T>(self, relation: impl Into<Include<M, T>>) -> Self
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>) -> Self
pub fn reading(self, reads: Reads<M>) -> Self
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) -> 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.