Table views DSL
v0.0.12
A view is a named table over the same resource, with its own columns and its own base filter. A mount picks it by name, and the table draws it in place of the table's own columns. The block sits inside the table block of a resource, next to columns. This page lists every option of a view. For a walk-through, see Build an admin table.
view
Declares one named view. It sits at mishka_gervaz.table.view.
Call: view name
Arguments:
| Argument | Type | Default | Description |
|---|---|---|---|
name | atom | none | Required. The view's name, the value of the mount's view assign. |
Options:
| Option | Type | Default | Description |
|---|---|---|---|
filter | any | none | A base filter every read of the view applies: an Ash expression such as expr(status == :refunded) or a keyword list. The reader cannot clear it. |
view columns
The columns of the view. It holds the column entities and takes the options of the table's columns section. It sits at mishka_gervaz.table.view.columns. A view has no auto_columns.
| Option | Type | Default | Description |
|---|---|---|---|
column_order | list(atom) | none | Column display order. Columns not in list appear at end. |
default_sort | any | none | The sort a fresh load of the view uses. Give a list of {field, :asc | :desc} tuples, or a keyword list such as default_sort refunded_at: :desc. |
column and its ui
A view column takes the same options and the same ui block as a column of the table. They sit at mishka_gervaz.table.view.columns.column and mishka_gervaz.table.view.columns.column.ui. See Table columns DSL for each option.
What a view keeps from the table
A view changes only its columns and its base filter. Everything else is the table's: identity, source (the read action too), filters, row_actions, bulk_actions, pagination, realtime, url_sync and presentation. A view preloads what its own columns need.
Rules checked when you compile
- A view declares at least one column. A view with none is reported as "declares no columns".
- Its columns follow the rules of the table's columns: a
staticcolumn needsrequires, and astaticcolumn that issortableneedssort_field.
Mount a view
Pass the view's name as the view assign of the table component. The table reads it when the component starts. A name the resource does not declare raises an ArgumentError that lists the views it does declare.
<.live_component
module={MishkaGervaz.Table.Web.Live}
id="refunds-table"
resource={MyApp.Shop.Order}
view={:refunds}
current_user={@current_user}
/>Two mounts of one resource on a page need different ids, because each has its own stream.
Introspection
MishkaGervaz.Resource.Info.Table.views/1 returns the views of a resource as a map of each name to its runtime config. view/2 returns one view's config, or nil. columns/2 takes a resource and a view name and returns the columns of that view, or the table's own columns when the name is nil.