pub struct Table<M> { /* private fields */ }Expand description
Table description of a Resource’s list view declaring columns and how they map to queries.
A clone shares every column, filter and projection.
The list keeps its whole state in the URL: ?q= searches, ?sort= and ?dir= sort,
?page=, ?per_page=, ?after= and ?before= page, ?f.<name>= filters and ?group_by=
groups. Each row is keyed by its record’s primary key, which the action URLs and bulk
checkboxes carry; a composite key has no URL form, so its rows render without row actions or
bulk selection.
- Search matches a row any searchable column contains the term in. It escapes
%and_, trims the term and caps it at 128 characters, and matches case-insensitively: PostgreSQL runs it asILIKE, SQLite (for ASCII) and MySQL (under its default collations) asLIKE. - Without a
?sort=naming a sortable column, the rows sort by thedefault_sort, else by the first sortable column, ascending. The primary key breaks ties, so a sort over duplicate values pages deterministically, and a page number past the last page reads as the last. - A filter that cannot apply, an unknown name, a value the filter rejects or one past the limits, is never dropped silently: the list shows a warning banner naming it, and the export answers 400. At most 32 filters apply, each with at most 64 values and parts, each name, part and value at most 256 bytes. Active filters combine with AND.
- Grouping runs on the loaded page, so its counts cover that page; a
?group_by=the table does not declare is ignored. - The list updates in place: a search, filter, sort or page reruns the page through the runtime, keeping focus and scroll, and without JavaScript its links and its search form load the page. A table that fails to load shows an error state with a retry link in place of the rows.
When the policy allows DeleteAny, or RunAny for an action placed on the bulk bar, the list
adds a checkbox column and a bulk bar; a row that no delete or bulk action allows gets no
checkbox. A bulk delete takes at most 400 records, runs in one transaction and skips the
records the policy refuses Delete. Both deletes ask first through a confirmation dialog,
which needs JavaScript; a POST not confirmed through it answers 400. Each lands back on the
list as it was left.
§Export
GET {list}/-/export returns the list as a CSV file named {slug}.csv, with the current
search, filters and sort applied and the relations the columns include loaded. It leaves out
the rows the policy refuses View, delivers at most 10,000 rows and answers 413 rather than a
truncated file when more match. It writes each column’s formatted value, a date column’s
stored value, and escapes a cell a spreadsheet would read as a formula; ?bom=1 prefixes the
file with a byte-order mark for Excel.
Implementations§
Source§impl<M> Table<M>
impl<M> Table<M>
Sourcepub fn default_sort<T>(self, path: impl Into<Path<M, T>>) -> Selfwhere
M: Model,
pub fn default_sort<T>(self, path: impl Into<Path<M, T>>) -> Selfwhere
M: Model,
Sort by path’s column, smallest first, when the URL names no sortable column; by the
first sortable column, ascending, by default.
use tablo_core::{Table, TextColumn, lens};
Table::new(TextColumn::new(lens!(Post.title)).sortable()).default_sort(lens!(Post.title));A path whose column the table does not declare sortable is a declaration error.
Sourcepub fn default_sort_desc<T>(self, path: impl Into<Path<M, T>>) -> Selfwhere
M: Model,
pub fn default_sort_desc<T>(self, path: impl Into<Path<M, T>>) -> Selfwhere
M: Model,
Sort by path’s column, largest first, when the URL names no sortable column, as
default_sort does ascending.
use tablo_core::{DateColumn, Table, TextColumn, lens};
// The newest posts first.
Table::new((
TextColumn::new(lens!(Post.title)).sortable(),
DateColumn::new(lens!(Post.published_at)).sortable(),
))
.default_sort_desc(lens!(Post.published_at));Sourcepub fn default_sort_by(self, sort: Sort) -> Self
pub fn default_sort_by(self, sort: Sort) -> Self
Sort by the sortable column sort names when the URL names none: the default for a
column of your own, whose name no field path spells.
A field’s column takes default_sort, whose path a rename fails
to compile.
use tablo_core::{Sort, Table, TextColumn, lens};
// "revenue" is the name a column of your own returns.
Table::new(TextColumn::new(lens!(Post.title))).default_sort_by(Sort::desc("revenue"));A name the table declares no sortable column for is a declaration error.
Source§impl<M> Table<M>
impl<M> Table<M>
Sourcepub fn new(cols: impl IntoColumns<M>) -> Self
pub fn new(cols: impl IntoColumns<M>) -> Self
Declare a table of cols.
Each row is keyed by its record’s primary key, which the row’s action URLs carry.
Sourcepub fn column(self, column: impl Column<M> + 'static) -> Self
pub fn column(self, column: impl Column<M> + 'static) -> Self
Append column after the declared ones.
Sourcepub fn filters(self, filters: impl IntoFilters<M>) -> Selfwhere
M: Model,
pub fn filters(self, filters: impl IntoFilters<M>) -> Selfwhere
M: Model,
Declare filters.
Sourcepub fn group_by<T>(self, lens: Lens<M, T>) -> Self
pub fn group_by<T>(self, lens: Lens<M, T>) -> Self
Offer grouping the page’s rows by the field lens reads, under the field’s name.
Sourcepub fn pagination(self, pagination: Pagination) -> Self
pub fn pagination(self, pagination: Pagination) -> Self
Page through the rows as pagination says; Pagination::Pages by default.
Sourcepub fn action_layout(self, layout: ActionLayout) -> Self
pub fn action_layout(self, layout: ActionLayout) -> Self
Put a row’s actions where layout says; ActionLayout::Inline by default.
Sourcepub fn per_page_options(self, options: impl IntoIterator<Item = usize>) -> Self
pub fn per_page_options(self, options: impl IntoIterator<Item = usize>) -> Self
The page sizes a reader may pick, beside the table’s own; none offers no choice.
DEFAULT_PER_PAGE_OPTIONS by default. A cursor table offers none.
Sourcepub fn declaration_errors(&self) -> Vec<DeclarationErrorKind>
pub fn declaration_errors(&self) -> Vec<DeclarationErrorKind>
What is wrong with this declaration.
Sourcepub fn pagination_mode(&self) -> Pagination
pub fn pagination_mode(&self) -> Pagination
How the table pages.
Sourcepub fn row_action_layout(&self) -> ActionLayout
pub fn row_action_layout(&self) -> ActionLayout
Where the table puts a row’s actions.
Sourcepub fn hide_search(self) -> Self
pub fn hide_search(self) -> Self
Render no search toolbar in the table.
Render no filter menu in the table’s toolbar.