howdy/ui/data_table
Data tables: rows of records with sortable columns and selectable rows.
let columns = [
data_table.column("id", "Invoice", fn(invoice) { text(invoice.id) }),
data_table.column("customer", "Customer", fn(invoice) { text(invoice.customer) })
|> data_table.sortable(fn(a, b) { string.compare(a.customer, b.customer) }),
data_table.column("amount", "Amount", fn(invoice) { text(money(invoice.amount)) })
|> data_table.sortable(fn(a, b) { int.compare(a.amount, b.amount) })
|> data_table.numeric,
]
data_table.new(columns, invoices)
|> data_table.sort(model.sort, by: data_table.Events(SortBy))
|> data_table.selectable(
key: fn(invoice) { invoice.id },
selected: model.selected,
toggle: fn(id) { [event.on_check(fn(_) { Toggle(id) })] },
toggle_all: [event.on_check(ToggleAll)],
)
|> data_table.empty([text("No invoices yet.")])
|> data_table.view
Sorting, selection and paging live on the server: the table shows the
rows it is given, sorted by the current Sort with the column’s own
comparison. A header click asks for the next sort, through a link on a
page or a message in a live view. Put a search box above the table and
howdy/ui/pagination below it to filter and page the rows you pass in.
Types
Values
pub fn caption(
table: DataTable(row, msg),
children: List(element.Element(msg)),
) -> DataTable(row, msg)
A caption under the table, which also names it for screen readers.
pub fn caption_class() -> css.Class
pub fn cell_class() -> css.Class
pub fn check_cell_class() -> css.Class
pub fn checkbox_class() -> css.Class
pub fn column(
key: String,
header: String,
cell: fn(row) -> element.Element(msg),
) -> Column(row, msg)
A column. key names it in a Sort.
pub fn columns_menu(
table: DataTable(row, msg),
id id: String,
label label: String,
toggle toggle: fn(String, Bool) -> List(
attribute.Attribute(msg),
),
) -> element.Element(msg)
A “Columns” button with a menu that turns each column on or off. id
names the menu; toggle gives the attributes of a column’s menu item,
such as a click handler, given its key and whether it is shown now.
Keep the hidden keys in your model and pass them to hide.
pub fn empty(
table: DataTable(row, msg),
children: List(element.Element(msg)),
) -> DataTable(row, msg)
What to show when there are no rows, instead of the words’
no_results.
pub fn empty_class() -> css.Class
pub fn head_class() -> css.Class
pub fn hide(
table: DataTable(row, msg),
keys: List(String),
) -> DataTable(row, msg)
Leave out the columns with these keys, such as those a person has
turned off with columns_menu.
pub fn indicator_class() -> css.Class
pub fn numeric(column: Column(row, msg)) -> Column(row, msg)
Align the column to the end, for numbers.
pub fn scroll_class() -> css.Class
pub fn selectable(
table: DataTable(row, msg),
key key: fn(row) -> String,
selected selected: List(String),
toggle toggle: fn(String) -> List(attribute.Attribute(msg)),
toggle_all toggle_all: List(attribute.Attribute(msg)),
) -> DataTable(row, msg)
Add a checkbox to each row and one to the header for all rows. key
identifies a row; rows whose key is in selected are checked.
toggle gives the attributes of a row’s checkbox, such as a check
handler, and toggle_all those of the header’s.
pub fn sort(
table: DataTable(row, msg),
sort: option.Option(Sort),
by by: SortBy(msg),
) -> DataTable(row, msg)
Sort the rows by sort, and make the headers of sortable columns ask
for a new sort through by.
pub fn sort_class() -> css.Class
pub fn sortable(
column: Column(row, msg),
compare: fn(row, row) -> order.Order,
) -> Column(row, msg)
Let the column be sorted, comparing rows with compare.
pub fn sorted_rows(table: DataTable(row, msg)) -> List(row)
The rows as table shows them: sorted by its current sort.
pub fn table_class() -> css.Class
pub fn view(table: DataTable(row, msg)) -> element.Element(msg)
pub fn words(
table: DataTable(row, msg),
words: words.Words,
) -> DataTable(row, msg)
Speak another language: the empty message and the selection checkboxes’ labels. English by default.