Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Writing a Column Type

A column type renders one kind of cell on any list that names it.

Implement the type

use laterite_admin::html::Markup;
use laterite_admin::list::{CellCx, CellVm, ColumnType, ColumnTypeReg};

struct Rating;

impl ColumnType for Rating {
    fn view_key(&self) -> &'static str { "acme.rating" }
    fn view_model(&self, cx: &CellCx<'_>) -> CellVm { /* ... */ }
    fn render_default(&self, vm: &CellVm) -> Markup { /* ... */ }
}
MethodRole
view_keyThe name a column’s type uses. A dotted vendor.name.
view_modelThe cell’s value as a view-model.
render_defaultThe markup.
option_keysThe keys the type reads from its column entry; any other key is refused at boot.
checkChecks the column’s keys when the list is read; an error stops the boot.
CellCxGives
valueThe stored value, as text.
tz, localeThe display timezone and locale.
optionsThe column’s entry, for the type’s own keys.
option_str(key)One of those keys, as text.
field(column)Another value in the row; field("id") is the record’s id.
icon(name)Inline SVG for an icon from the set.
base()The admin mount, for an address inside the admin.
CellCx::new(value, tz, locale)A context for a test, with with_options, with_row, with_icons, with_base.

Register it

registry.add(ColumnTypeReg::new(Arc::new(Rating)));
columns:
  rating: { type: acme.rating }

A taken key aborts the boot; so does a column naming a key nobody registered.