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.

OptionTypeDefaultDescription
column_orderlist(atom)noneColumn display order. Columns not in list appear at end.
default_sortanynoneThe 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:

ArgumentTypeDefaultDescription
nameatomnoneRequired. Column identifier.

Options:

OptionTypeDefaultDescription
sourceatom | {atom, atom} | {atom, list(atom)} | list(atom | {atom, atom})noneWhere 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.
sortablebooleanfalseEnable sorting.
searchablebooleanfalseInclude 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.
filterablebooleanfalseAuto-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.
visibleboolean | (any -> any)trueStatic or dynamic visibility.
positionanynoneColumn position (integer, :first, :last, {:before, :col}, {:after, :col}).
exportbooleantrueInclude 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_asatomnoneField 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.
defaultanynoneDefault value when source is nil.
separatorString.t" "Separator for merged fields.
staticbooleanfalseMarks a column with no database source, one that is computed or fixed. Pair it with requires.
requireslist(atom)[]The fields a static column reads. A render function receives them as a map.
sort_fieldlist(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)noneChanges the value before it is drawn. fn value -> ... end or fn state, record, value -> ... end.
render(any -> any) | (any, any -> any)noneCustom 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.
labelString.t | (-> any)noneThe 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.

OptionTypeDefaultDescription
labelString.t | (-> any)noneHeader 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.
widthString.tnoneCSS width (e.g., "200px", "20%").
min_widthString.tnoneCSS min-width. The value is compiled into the config, but no built-in template or handler reads it.
max_widthString.tnoneCSS max-width. The value is compiled into the config, but no built-in template or handler reads it.
align:left | :center | :right:leftText alignment. The value is compiled into the config, but no built-in template or handler reads it.
classString.tnoneCell CSS classes. A value replaces the default classes of the cell.
header_classString.tnoneHeader cell CSS classes. A value replaces the default classes of the header cell.
extramap%{}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.

OptionTypeDefaultDescription
exceptlist(atom)[]Exclude these attributes.
onlylist(atom)noneOnly these attributes (overrides except).
position:start | :end:endWhere to place auto columns.

defaults

Default options for the discovered columns. It sits at mishka_gervaz.table.columns.auto_columns.defaults.

OptionTypeDefaultDescription
sortablebooleanfalseDefault sortable value.
searchablebooleanfalseDefault searchable value. The value is compiled into the config, but no built-in template or handler reads it.
visiblebooleantrueDefault visible value.
exportbooleantrueDefault 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.

OptionTypeDefaultDescription
boolean_true_labelString.t"Yes"Default label for boolean true. Gervaz does not compile it into the config, so nothing reads it.
boolean_false_labelString.t"No"Default label for boolean false. Gervaz does not compile it into the config, so nothing reads it.
datetime_formatatom:mediumDefault datetime format. Gervaz does not compile it into the config, so nothing reads it.
text_truncateintegernoneDefault 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:

ArgumentTypeDefaultDescription
nameatomnoneRequired. Column name to override.

Options:

OptionTypeDefaultDescription
sortablebooleannoneOverride sortable.
searchablebooleannoneOverride searchable. The value is compiled into the config, but no built-in template or handler reads it.
visiblebooleannoneOverride visible.
exportbooleannoneOverride export. The value is compiled into the config, but no built-in template or handler reads it.
format(any -> any) | (any, any, any -> any)noneValue 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.

OptionTypeDefaultDescription
labelString.t | (-> any)noneHeader 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.
widthString.tnoneCSS width (e.g., "200px", "20%").
min_widthString.tnoneCSS min-width. The value is compiled into the config, but no built-in template or handler reads it.
max_widthString.tnoneCSS max-width. The value is compiled into the config, but no built-in template or handler reads it.
align:left | :center | :right:leftText alignment. The value is compiled into the config, but no built-in template or handler reads it.
classString.tnoneCell CSS classes. A value replaces the default classes of the cell.
header_classString.tnoneHeader cell CSS classes. A value replaces the default classes of the header cell.
extramap%{}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.