pub struct ToggleColumn<M> { /* private fields */ }Expand description
A column of a bool field rendered as a switch that saves the record when it flips.
tablo_core::ToggleColumn::new(tablo_core::lens!(Post.featured));See Editing in a cell for where the switch renders and what it posts.
§Editing in a cell
A list, a relation table or a widget’s record table renders the control on a row whose record the user may update and that is not in the trash, for a field the user may change; anywhere else, and on a detail page, the cell shows the value. The control posts its field alone to the record’s edit route, with the record’s version, so the save runs every check the edit page’s does and lands back on the table. A refused value opens the edit page with its errors.
The mount refuses the column unless the resource’s form edits the field with the matching control, a checkbox or switch here, shown and enabled whatever the other fields hold. Flipping the switch and changing a select save through the runtime’s one line of script; a text input saves on Enter.
The control spells the value as the field’s form spelling, as a derived record form does, so a
hand-written RecordForm must read the key as that spelling.
Implementations§
Source§impl<M> ToggleColumn<M>where
M: Model,
impl<M> ToggleColumn<M>where
M: Model,
Sourcepub fn new(lens: Lens<M, bool>) -> ToggleColumn<M>
pub fn new(lens: Lens<M, bool>) -> ToggleColumn<M>
Bind the column to the bool field lens reads.
Sourcepub fn label(self, label: impl Into<Text>) -> ToggleColumn<M>
pub fn label(self, label: impl Into<Text>) -> ToggleColumn<M>
Replace the label the field’s name gives it.
Sourcepub fn width(self, width: ColumnWidth) -> ToggleColumn<M>
pub fn width(self, width: ColumnWidth) -> ToggleColumn<M>
Declare this column’s width.
Sourcepub fn toggleable(self) -> ToggleColumn<M>
pub fn toggleable(self) -> ToggleColumn<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.
Sourcepub fn sortable(self) -> ToggleColumn<M>
pub fn sortable(self) -> ToggleColumn<M>
Make the header a sort link.
Trait Implementations§
Source§impl<M> Clone for ToggleColumn<M>
impl<M> Clone for ToggleColumn<M>
Source§fn clone(&self) -> ToggleColumn<M>
fn clone(&self) -> ToggleColumn<M>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<M> Column<M> for ToggleColumn<M>
impl<M> Column<M> for ToggleColumn<M>
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.