Skip to main content

Column

Struct Column 

Source
#[non_exhaustive]
pub struct Column { /* private fields */ }
Expand description

One column of a Grid; build it with a constructor per Kind.

Implementations§

Source§

impl Column

Source

pub fn related( key: &str, label: &str, table: &str, foreign_key: &str, column: &str, ) -> Self

A value of the row this one belongs to: table’s column where its id is this row’s foreign_key (Column::related("customer", "Customer", "customers", "customer_id", "name")). Shown, sorted, filtered and searched like a text column (.numeric() for a number), in one query per page.

Source

pub fn count_of(key: &str, label: &str, table: &str, foreign_key: &str) -> Self

How many rows of table point at this row through foreign_key (Column::count_of("notes", "Notes", "order_notes", "order_id")).

Source

pub fn sum_of( key: &str, label: &str, table: &str, foreign_key: &str, column: &str, ) -> Self

The total of column over the rows of table that point at this row through foreign_key.

Source

pub fn computed(self, sql: &str) -> Self

The column’s value is sql, a scalar SQL expression over the row, where {T} stands for the model’s table: stock value as Column::money("value", "Value").computed("{T}.\"on_hand\" * (SELECT \"cost\" FROM \"variants\" WHERE \"id\" = {T}.\"variant_id\")"). It is shown, sorted, filtered, searched, summed (Column::summary) and grouped by (Grid::groups) like a related column, with no database view. sql is written by the app, never taken from a request: values go in the model’s columns and subqueries, not in the string.

Source

pub fn numeric(self) -> Self

Shows a related value as a number (filtered with a range).

Source

pub fn image(key: &str, label: &str) -> Self

An image column: the value is the image’s URL (.round() for avatars).

Source

pub fn color(key: &str, label: &str) -> Self

A color column: a swatch of the CSS color in the value, with its code.

Source

pub fn badges(self, tones: &[(&str, &str)]) -> Self

Values as colored badges: (value, tone) pairs, the tone one of success, warning, danger, info or neutral. Values not listed get a neutral badge; .badges(&[]) makes every value one.

Source

pub fn icons(self) -> Self

Yes/no columns as a check and a cross instead of words.

Source

pub fn description(self, key: &str) -> Self

Another of the row’s values, small under this one (an email under a name).

Source

pub fn tooltip(self, key: &str) -> Self

Another of the row’s values, shown when the cell is hovered.

Source

pub fn wrap(self) -> Self

Long text wraps instead of widening the column.

Source

pub fn limit(self, chars: usize) -> Self

Text past chars characters is cut with … (the whole text shows on hover).

The value links to this URL ({id} is the row’s id).

Source

pub fn copyable(self) -> Self

A button next to the value copies it.

Source

pub fn round(self) -> Self

Images round (avatars).

Source

pub fn text(key: &str, label: &str) -> Self

A text column; key is the model’s column.

Source

pub fn number(key: &str, label: &str) -> Self

A number column (.decimals(n) for a fixed number of decimals).

Source

pub fn money(key: &str, label: &str) -> Self

An amount in the smallest unit (cents, fils), shown in whole units of APP_CURRENCY with its usual decimals (129900 cents is 1,299.00 in USD, 400,000 in IDR), as the money template filter takes it. Summaries and exports show whole units too, and range filters take them. An inline edit still sends the stored value (the smallest unit).

Source

pub fn date(key: &str, label: &str) -> Self

A date column.

Source

pub fn datetime(key: &str, label: &str) -> Self

A date and time column (shown in APP_TIMEZONE).

Source

pub fn bool(key: &str, label: &str) -> Self

A yes/no column.

Source

pub fn select<V: Into<String>, L: Into<String>>( key: &str, label: &str, options: impl IntoIterator<Item = (V, L)>, ) -> Self

One of options (stored value, label shown).

Source

pub fn tags<V: Into<String>, L: Into<String>>( key: &str, label: &str, options: impl IntoIterator<Item = (V, L)>, ) -> Self

Several of options, stored as a JSON array of the values.

Source

pub fn custom(key: &str, label: &str) -> Self

A column the page’s template draws ({% call(row, column) grid(…) %}). key needn’t be a database column.

Source

pub fn under<S: Into<String>>(self, groups: impl IntoIterator<Item = S>) -> Self

Puts the column under grouped headings, outermost first: .under(["Amounts"]), .under(["Sales", "Q1"]). Neighbouring columns under the same headings share them.

Source

pub fn sortable(self, sortable: bool) -> Self

Whether a click on the heading sorts by this column (default: yes, except for tags and custom columns).

Source

pub fn filterable(self, filterable: bool) -> Self

Whether the heading has a filter (default: yes, except for custom columns).

Source

pub fn mobile(self) -> Self

Shown on small screens until the user picks otherwise. When no column says so, the first three are.

Source

pub fn hidden(self) -> Self

Hidden on wide screens too until the user turns it on.

Source

pub fn frozen(self) -> Self

Frozen at the left edge until the user picks otherwise.

Source

pub fn frozen_right(self) -> Self

Frozen at the right edge (e.g. a column of actions).

Source

pub fn decimals(self, decimals: u8) -> Self

Shows a number with exactly decimals decimals.

Source

pub fn width(self, width: &str) -> Self

A minimum width in CSS units, e.g. "14rem".

Source

pub fn editable(self) -> Self

Cells can be edited in place (double-click, Enter or F2; Enter saves, Escape cancels) and in the row’s edit mode. Saving sends the value to the grid’s Grid::edit_url. Not for custom columns, nor for merged ones.

Source

pub fn merge(self) -> Self

Neighbouring rows with the same value share one cell. Merged columns nest from left to right: a column merges only within the merged groups of the merged columns before it (Region, then City). Merging is off while rows are dragged into order.

Source

pub fn searchable(self) -> Self

The toolbar’s search box looks in this column (as text, ignoring case). The box shows when a column is searchable. Not for custom columns.

When the grid’s model has a full-text index (#[model(search = …)], see renox::db::search), the box searches through it instead: every column of the index counts (also those the grid doesn’t show), words match their other forms and prefixes, and rows come best match first until the user sorts. Searchable columns outside the index are still matched as text.

Source

pub fn summary(self, summary: Summary) -> Self

A figure over every row the filters match, in the grid’s footer and under each group: .summary(Summary::Sum), several in a row (.summary(Summary::Sum).summary(Summary::Average)). Sum, average and range are for number and money columns; count for any.

Source

pub fn key(&self) -> &str

The column’s key.

Source

pub fn kind(&self) -> Kind

The column’s kind.

Source

pub fn label(&self) -> &str

The column’s heading.

Source

pub fn titled(self, label: &str) -> Self

The same column under another heading, e.g. a translation.

Source

pub fn options(&self) -> &[(String, String)]

The (value, label) choices of a select or tags column (empty for the other kinds).

Trait Implementations§

Source§

impl Clone for Column

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 Debug for Column

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: RngExt + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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