Ledger UI's tables: basic, bordered, hoverable, zebra, the grid and the lean data looks, with
:col slots the way Phoenix's generated CoreComponents.table/1 takes them.
<.table id="users" rows={@users}>
<:col :let={user} label="Name">{user.name}</:col>
<:col :let={user} label="Job" align="right">{user.job}</:col>
</.table>
<.table id="users" rows={@streams.users} variant="hoverable"
row_click={fn {_id, user} -> JS.navigate(~p"/users/#{user.id}") end}>
<:col :let={{_id, user}} label="Name" sort_key="name">{user.name}</:col>
<:action :let={{_id, user}}><.button size="sm">Edit</.button></:action>
</.table>The markup is div.lu-tablewrap > table.lu-table.<variant>; the look lives in ledger.css.
variant is nil for the bare lu-table; rounded (row, top) rounds the header row.
Events
Every event attr takes an event name or a %JS{}; target sets phx-target.
on_sort:%{"column" => sort_key, "direction" => "asc" | "desc"}(the direction to sort by next). A column withsort_keygetsclass="sort"and the arrows;sort_by/sort_dirmark the current order.
key ison_select: `%{"id" => key, "selected" => "true""false"}` (the new state of that row). on_select_all: `%{"selected" => "true""false"} .selected` lists the checked keys; therow_key.(row)or the row's DOM id. With a stream,stream_insertthe rows whose selection changed and giveall_selected.
Hand-written tables
Without rows, the table renders its inner block: table_head/1, table_body/1,
table_row/1, table_cell/1, table_foot/1 and table_empty/1 (see each).
Columns that leave by priority
A :col with priority 1, 2 or 3 leaves (header, cells and :foot cell together) when the
table's own box gets narrower than 720, 560 and 420px (a container query scoped to the table's
id). table-narrow-hide hides what carries it under 420px.
Card layout, details panel, copy columns (used by card_table/1)
Extra attributes card_below, details, row_editing, row_action and the column attributes
role, width, truncate, card, copy* back the "card" table (see
LedgerUI.Components.CardTable): under card_below px each row is a two-line grid placed by the
role of its cells (head, status, title, value); details adds a panel under the clicked
row (hook LedgerUI.CardTable) with the :detail slots and the columns that left by priority;
copy turns a cell into a copy button; row_editing swaps a row for the :edit slot.
Not implemented
peek / peek_label (the panel with the hidden columns) and bleed are accepted but draw
nothing yet. borderless only adds the borderless class (the stylesheet has no rule for it).
Summary
Functions
The JS that opens or closes the detail row of the row with DOM id row_id
(table_expand_toggle/1 and table_detail_row/1).
Functions
Attributes
id(:string) (required)rows(:any) - A list or a@streams.xstream. Leave it out to write the table by hand. Defaults tonil.row_id(:any) - Function giving each row's DOM id (streams: the stream id). Defaults tonil.row_click(:any) - Function of the row returning aJSor an event. Defaults tonil.row_class(:any) - Function of the row returning extra classes of its<tr>. Defaults tonil.row_attrs(:any) - Function of the row returning a map of extra<tr>attributes. Defaults tonil.row_item(:any) - Maps each row before the slots get it. Defaults to&Function.identity/1.row_key(:any) - Function giving the selection key of a row (default: DOM id). Defaults tonil.variant(:string) -nilis the barelu-table.gridis the gridjs look;data/data-gridthe lean one ofdata_table/1. Defaults tonil. Must be one ofnil,"basic","bordered","hoverable","zebra","grid","data","data-grid", or"flat".rounded(:string) - Defaults tonil.Must be one ofnil,"row","top", or"none".sort_by(:string) - Defaults tonil.sort_dir(:string) - Defaults to"asc". Must be one of"asc", or"desc".on_sort(:any) - Defaults tonil.on_select(:any) - Defaults tonil.on_select_all(:any) - Defaults tonil.selected(:list) - Defaults to[].all_selected(:boolean) - Defaults tonil.hoverable(:boolean) - Defaults tonil.compact(:boolean) - Defaults tofalse.headless(:boolean) - Defaults tofalse.sticky_header(:boolean) - Defaults tofalse.borderless(:boolean) - Defaults tofalse.bleed(:boolean) - Not implemented yet. Defaults tofalse.card_below(:integer) - Width (px) of the table's own box under which rows become two-line cards (needsroles). Defaults tonil.details(:boolean) - A click on a row opens a panel under it (hookLedgerUI.CardTable). Defaults tofalse.panel_label(:string) - Defaults to"Details".row_editing(:any) - Function of the row; true swaps its cells for the:editslot. Defaults tonil.row_action(:any) - Function of the row; false leaves the content of its:actioncells out. Defaults tonil.body_class(:any) - Classes of the<tbody>. Defaults tonil.select_attrs(:any) - Function of the row returning extra attributes (class,style) of its checkbox label. Defaults tonil.expand_open(:any) - Function of the row: with:expand, shows its detail row always open (no toggle column), for rows it returns true for. Defaults tonil.breakpoints(:list) - Widths (px) under which priority 1, 2, 3... leave. Defaults to[720, 560, 420].wrapper(:boolean) -falseleaves out thelu-tablewrapbox (a table inside alu-card-b). Defaults totrue.container(:boolean) - Defaults tonil.peek(:boolean) - Not implemented yet. Defaults tofalse.peek_label(:string) - Defaults to"Hidden columns".target(:any) - Defaults tonil.expand_label(:string) - Defaults tonil.scroll_label(:string) - Defaults tonil.sort_label(:string) - Defaults tonil.row_label(:any) - Defaults tonil.select_all_label(:string) - Defaults to"Select all rows".select_label(:string) - Defaults to"Select row".wrapper_class(:any) - Defaults tonil.class(:any) - Classes of the<table>. Defaults tonil.- Global attributes are accepted. Attributes of the
<table>.
Slots
action- Cells appended to every row, after the columns. Accepts attributes:priority(:integer) - Leaves with the columns of that priority.card(:boolean) -falseleaves the cell out of the card layout.
col- A column; receives the row (afterrow_item). Accepts attributes:label(:string)class(:any)head_class(:any)align(:string) - Must be one of"left","center", or"right".sort_key(:string)priority(:integer)style(:string) - Inline style of the cell (<td>).role(:string) - Must be one of"head","status","title","value", or"meta".width(:string) - CSS track:max-content(default) orminmax(120px,1.3fr).truncate(:boolean)card(:boolean) - Keeps the cell in the card layout, in a line of its own.copy(:any) - Function of the row returning the text a copy button copies.copy_label(:string)copied_label(:string)copy_show(:string) - Must be one of"inline".copy_tip(:string) - Must be one of"value_label".
detail- Alabel: valueline of the details panel; receives the row. Accepts attributes:label(:string)
edit- Inline form in place of the cells of a row for whichrow_editingis true.empty- Shown in a full-width row when there are no rows.expand- Detail shown under a row; receives%{row: row, toggle: js}.foot- A cell of the<tfoot>row, for totals. Accepts attributes:class(:any)align(:string) - Must be one of"left","center", or"right".colspan(:any)priority(:integer)
inner_block- The hand-written table whenrowsis not given.
Attributes
class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
Attributes
header(:boolean) - Renders a<th scope="row">. Defaults tofalse.align(:string) - Defaults tonil.Must be one ofnil,"left","center", or"right".colspan(:any) - Defaults tonil.rowspan(:any) - Defaults tonil.priority(:integer) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block
Attributes
id(:string) - Defaults tonil.checked(:boolean) - Defaults tofalse.indeterminate(:boolean) - Draws the dash of a partial selection (needs anid, for its hook). Defaults tofalse.label(:string) (required) - Thearia-labelof the box.on_click(:any) - Defaults tonil.values(:map) - Sent asphx-value-*withon_click. Defaults to%{}.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted. Attributes of the
<label>.
Attributes
row_id(:string) (required)open(:boolean) - Defaults tofalse.class(:any) - Classes of the detail panel. Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
Attributes
id(:string) (required)class(:any) - Classes of the cell. Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
Attributes
row_id(:string) (required)open(:boolean) - Defaults tofalse.label(:string) - Defaults to"Toggle details".class(:any) - Defaults tonil.- Global attributes are accepted.
Attributes
class(:any) - Classes of the:cellrow. Defaults tonil.- Global attributes are accepted.
Slots
cell- A<td>of the totals row. Accepts attributes:class(:any)align(:string) - Must be one of"left","center", or"right".colspan(:any)priority(:integer)
inner_block- Free<tr>rows after the:cellrow.
Attributes
sort_by(:string) - Defaults tonil.sort_dir(:string) - Defaults to"asc". Must be one of"asc", or"desc".on_sort(:any) - Defaults tonil.on_select_all(:any) - Adds a select-all checkbox cell first; the event it sends. Defaults tonil.all_selected(:boolean) - Defaults tofalse.some_selected(:boolean) - Defaults tofalse.select_all_id(:string) - Defaults tonil.select_all_label(:string) - Defaults to"Select all rows".sort_label(:string) - Defaults tonil.target(:any) - Defaults tonil.sticky_header(:boolean) - Defaults tofalse.class(:any) - Classes of the<tr>. Defaults tonil.- Global attributes are accepted. Attributes of the
<thead>.
Slots
col- A header cell; its content is the label (or givelabel). Accepts attributes:label(:string)class(:any)align(:string) - Must be one of"left","center", or"right".colspan(:any)priority(:integer)sort_key(:string)title(:string)id(:string)
inner_block- Extra<th>cells after the columns, or further header rows.
Attributes
selected(:boolean) -truechecks the box and marks the row (sel). Defaults tonil.on_click(:any) - Defaults tonil.on_select(:any) - Adds a selection checkbox cell first; the event it sends. Defaults tonil.select_value(:any) - Sent as"id"by the checkbox. Defaults tonil.select_label(:string) - Defaults to"Select row".target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
cell- A<td>of the row. Accepts attributes:class(:any)align(:string) - Must be one of"left","center", or"right".colspan(:any)rowspan(:any)priority(:integer)title(:string)id(:string)
inner_block- Free cells after the:cellones.
Attributes
id(:string) (required)rows(:integer) - Defaults to5.columns(:list) - Header labels; one column each. Defaults to[].cols(:integer) - How many columns whencolumnsis empty. Defaults to4.variant(:string) - Defaults tonil.Must be one ofnil,"basic","bordered","hoverable","zebra","grid","data","data-grid", or"flat".rounded(:string) - Defaults tonil.Must be one ofnil,"row","top", or"none".compact(:boolean) - Defaults tofalse.headless(:boolean) - Defaults tofalse.shapes(:list) - Per column:text(a bar),avatar,pillornumber. Defaults to[].label(:string) - Defaults to"Loading".class(:any) - Defaults tonil.- Global attributes are accepted.
The JS that opens or closes the detail row of the row with DOM id row_id
(table_expand_toggle/1 and table_detail_row/1).