Table columns DSL
v0.0.1
The columns section of a resource's table block declares the cells of the table: where each value comes from, whether it sorts and how it is drawn. Columns can also be discovered from the resource's attributes with auto_columns.
columns
Holds the column entities and two table-wide options. It sits at mishka_gervaz.table.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 uses. Give a list of {field, :asc | :desc} tuples. A keyword list such as default_sort featured: :desc, inserted_at: :desc also works. A bare atom or a single tuple is ignored. |
column
Declares one column. The inline form works too: column :inserted_at, sortable: true. It sits at mishka_gervaz.table.columns.column.
Call: column name
Arguments:
| Argument | Type | Default | Description |
|---|---|---|---|
name | atom | none | Required. Column identifier. |
Options:
| Option | Type | Default | Description |
|---|---|---|---|
source | atom | {atom, atom} | {atom, list(atom)} | list(atom | {atom, atom}) | none | Where the value comes from. Defaults to the column name. :field reads record.field. {:relation, :field} reads record.relation.field. [:field1, :field2] joins several fields with separator. [{:user, :name}, :title] mixes nested and direct fields. A source of the form {atom, [atom]} gives no value. |
sortable | boolean | false | Enable sorting. |
searchable | boolean | false | Include in global text search. The value is compiled into the config, but no built-in template or handler reads it. For text search, declare a :text filter with fields. |
filterable | boolean | false | Auto-create filter for this column. The value is compiled into the config, but no built-in template or handler reads it. Declare the filter in filters. |
visible | boolean | (any -> any) | true | Static or dynamic visibility. |
position | any | none | Column position (integer, :first, :last, {:before, :col}, {:after, :col}). |
export | boolean | true | Include in CSV/Excel export. The value is compiled into the config, but no built-in template or handler reads it. Gervaz has no built-in export. |
export_as | atom | none | Field name in export. Defaults to column name. The value is compiled into the config, but no built-in template or handler reads it. Gervaz has no built-in export. |
default | any | none | Default value when source is nil. |
separator | String.t | " " | Separator for merged fields. |
static | boolean | false | Marks a column with no database source, one that is computed or fixed. Pair it with requires. |
requires | list(atom) | [] | The fields a static column reads. A render function receives them as a map. |
sort_field | list(atom) | [] | The database field or fields to sort by. Required for a column that is both static and sortable. |
format | (any -> any) | (any, any, any -> any) | none | Changes the value before it is drawn. fn value -> ... end or fn state, record, value -> ... end. |
render | (any -> any) | (any, any -> any) | none | Custom HEEx for the cell. The first argument is the formatted value. For a static column with requires it is a map of exactly the required fields. With two arguments the function also gets the state, so it can read state.master_user? and state.current_user. |
label | String.t | (-> any) | none | The header text: a string, or fn -> dgettext(...) end. The built-in table header reads this option. Without it, the header is the humanized column name. |
column ui
How the cell and its header are drawn. It sits at mishka_gervaz.table.columns.column.ui.
| Option | Type | Default | Description |
|---|---|---|---|
label | String.t | (-> any) | none | Header text. String or fn -> gettext(...) end for i18n. The built-in table header reads the column's own label option, not this one. |
type | :text | :boolean | :badge | :bars | :number | :currency | :percentage | :date | :datetime | :time | :link | :image | :avatar | :avatars | :tags | :progress | :json | :uuid | :array | :custom | module | :text with a ui block. Without one, the type is inferred from the attribute. | How the value is drawn. :text is the default. A module that implements the ColumnType behaviour also works. Built-in renderers exist for :text, :boolean, :number, :date, :datetime, :uuid, :array, :badge, :bars, :tags, :avatars and :link. The schema also accepts :currency, :percentage, :time, :image, :avatar, :progress, :json and :custom, which have no built-in renderer. See Built-in types. |
width | String.t | none | CSS width (e.g., "200px", "20%"). |
min_width | String.t | none | CSS min-width. The value is compiled into the config, but no built-in template or handler reads it. |
max_width | String.t | none | CSS max-width. The value is compiled into the config, but no built-in template or handler reads it. |
align | :left | :center | :right | :left | Text alignment. The value is compiled into the config, but no built-in template or handler reads it. |
class | String.t | none | Cell CSS classes. A value replaces the default classes of the cell. |
header_class | String.t | none | Header cell CSS classes. A value replaces the default classes of the header cell. |
extra | map | %{} | Options for the column type, such as the colors of a :badge. The schema does not check the keys. Each type lists its own on the built-in types page. |
auto_columns
Discovers columns from the attributes of the resource, public or not, and merges them with the columns you declare. Declared columns keep their own positions. It sits at mishka_gervaz.table.columns.auto_columns.
| Option | Type | Default | Description |
|---|---|---|---|
except | list(atom) | [] | Exclude these attributes. |
only | list(atom) | none | Only these attributes (overrides except). |
position | :start | :end | :end | Where to place auto columns. |
defaults
Default options for the discovered columns. It sits at mishka_gervaz.table.columns.auto_columns.defaults.
| Option | Type | Default | Description |
|---|---|---|---|
sortable | boolean | false | Default sortable value. |
searchable | boolean | false | Default searchable value. The value is compiled into the config, but no built-in template or handler reads it. |
visible | boolean | true | Default visible value. |
export | boolean | true | Default export value. The value is compiled into the config, but no built-in template or handler reads it. |
ui_defaults
Default UI options for the discovered columns. It sits at mishka_gervaz.table.columns.auto_columns.ui_defaults.
| Option | Type | Default | Description |
|---|---|---|---|
boolean_true_label | String.t | "Yes" | Default label for boolean true. Gervaz does not compile it into the config, so nothing reads it. |
boolean_false_label | String.t | "No" | Default label for boolean false. Gervaz does not compile it into the config, so nothing reads it. |
datetime_format | atom | :medium | Default datetime format. Gervaz does not compile it into the config, so nothing reads it. |
text_truncate | integer | none | Default text truncate length. Gervaz does not compile it into the config, so nothing reads it. |
override
Overrides one discovered column. It sits at mishka_gervaz.table.columns.auto_columns.override.
Call: override name
Arguments:
| Argument | Type | Default | Description |
|---|---|---|---|
name | atom | none | Required. Column name to override. |
Options:
| Option | Type | Default | Description |
|---|---|---|---|
sortable | boolean | none | Override sortable. |
searchable | boolean | none | Override searchable. The value is compiled into the config, but no built-in template or handler reads it. |
visible | boolean | none | Override visible. |
export | boolean | none | Override export. The value is compiled into the config, but no built-in template or handler reads it. |
format | (any -> any) | (any, any, any -> any) | none | Value formatter: fn value -> ... end or fn state, record, value -> ... end. |
override ui
The ui block of an override. It takes the same options as a column ui block. It sits at mishka_gervaz.table.columns.auto_columns.override.ui.
| Option | Type | Default | Description |
|---|---|---|---|
label | String.t | (-> any) | none | Header text. String or fn -> gettext(...) end for i18n. The built-in table header reads the column's own label option, not this one. |
type | :text | :boolean | :badge | :bars | :number | :currency | :percentage | :date | :datetime | :time | :link | :image | :avatar | :avatars | :tags | :progress | :json | :uuid | :array | :custom | module | :text with a ui block. Without one, the type is inferred from the attribute. | How the value is drawn. :text is the default. A module that implements the ColumnType behaviour also works. Built-in renderers exist for :text, :boolean, :number, :date, :datetime, :uuid, :array, :badge, :bars, :tags, :avatars and :link. The schema also accepts :currency, :percentage, :time, :image, :avatar, :progress, :json and :custom, which have no built-in renderer. See Built-in types. |
width | String.t | none | CSS width (e.g., "200px", "20%"). |
min_width | String.t | none | CSS min-width. The value is compiled into the config, but no built-in template or handler reads it. |
max_width | String.t | none | CSS max-width. The value is compiled into the config, but no built-in template or handler reads it. |
align | :left | :center | :right | :left | Text alignment. The value is compiled into the config, but no built-in template or handler reads it. |
class | String.t | none | Cell CSS classes. A value replaces the default classes of the cell. |
header_class | String.t | none | Header cell CSS classes. A value replaces the default classes of the header cell. |
extra | map | %{} | Options for the column type, such as the colors of a :badge. The schema does not check the keys. Each type lists its own on the built-in types page. |