Data Table
Anatomy
Table with sorting, filtering, pagination, and row selection.
maud_ui::primitives::data_table
Props
Generated from public Rust fields. Defaults are evaluated from the implementation.
| Prop | Type | Default | Description |
|---|---|---|---|
id | String | "data-table" | No description |
columns | Vec<Column> | [] | No description |
rows | Vec<Vec<String>> | [] | No description |
rich_rows | Vec<Vec<CellMarkup>> | [] | Rich-markup rows. When non-empty, takes precedence over rows and each cell renders its CellMarkup::content (avatars, badges, buttons, etc.) with optional right-alignment. Mirrors table::Props.rich_rows. Backwards-compat: when empty (the default), the plain rows path is used unchanged — existing consumers need no migration. Sorting/filtering use plain row values, or visible text for rich rows. The runtime reorders original row nodes, preserving markup, controls and alignment. |
page_size | usize | 5 | No description |
searchable | bool | false | No description |
search_placeholder | String | "Filter..." | No description |
selectable | bool | false | When true, prepend a "Select all" checkbox column with per-row checkboxes. Matches shadcn's DataTable row-selection pattern. |
Examples
Searchable, sortable, paginated (5 per page)
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV001 | Paid | Credit Card | $250.00 |
| INV002 | Pending | PayPal | $150.00 |
| INV003 | Unpaid | Bank Transfer | $350.00 |
| INV004 | Paid | Credit Card | $450.00 |
| INV005 | Paid | PayPal | $550.00 |
| INV006 | Pending | Bank Transfer | $200.00 |
| INV007 | Paid | Credit Card | $300.00 |
| INV008 | Unpaid | PayPal | $400.00 |
| INV009 | Paid | Bank Transfer | $500.00 |
| INV010 | Pending | Credit Card | $275.00 |
Selectable rows + view options
| Name | Role | |
|---|---|---|
| Alice | Admin | |
| Bob | Editor |
Standalone column_header() helper
| Sortable column | Amount |
|---|
Usage and composition
Import
use maud_ui::primitives::data_table::{self, Props, Column};
Example
use maud::html;
use maud_ui::primitives::data_table;
let columns = vec![
data_table::Column {
key: "name".to_string(),
label: "Name".to_string(),
sortable: true, ..Default::default()
},
];
let rows = vec![
vec!["Alice".to_string()],
vec!["Bob".to_string()],
];
html! {
(data_table::render(data_table::Props {
id: "tbl".to_string(),
columns,
rows,
page_size: 5,
searchable: true,
search_placeholder: "Filter...".to_string(),
selectable: true,
}))
}
Column Struct
| Field | Type | Default | Description |
|---|---|---|---|
key | String | — | Unique column identifier |
label | String | — | Column header text |
sortable | bool | false | Whether column can be sorted (shows icon if true) |
align | Align | Left | Left, Center or Right. Applied to headers and body; rich cell align_right overrides to Right. |
Helper Functions
column_header(label, sortable) → Markup
Renders a <th> with optional sort icon and aria-sort attribute. Use when constructing custom table headers.
view_options(columns) → Markup
Renders a "Columns ▾" dropdown trigger stub for toggling column visibility. Placeholder implementation; wiring toggles is deferred.
Features
- Pagination: Previous/Next buttons in footer; rows outside page size are
hidden - Selection: When
selectable: true, prepends "Select all" checkbox in header and per-row checkboxes - Row data: Each row stored in
data-row-dataas JSON array for client script access - Sorting: Sortable columns emit
data-sortable="true"with chevron icon andaria-sortattribute
Related
- Table
- Checkbox
- Input (search)
Shadcn reference
https://ui.shadcn.com/docs/components/data-table
column_header_aligned(label, sortable, Align::Right) → Markup
The original two-argument helper keeps left alignment; the aligned helper supports Left, Center and Right. Use Right for numeric columns. Column now has align: Align and implements Default; add ..Default::default() when migrating existing literals. Header cells remain muted and medium weight. Sortable headers respond to Enter/Space as well as clicks and announce their sort state. Runtime sorting/pagination moves existing rows, preserving alignment, rich content, checkbox state and attached controls. Rich rows sort/filter by their visible cell text; server-side rich filtering remains an application choice.
Exact numeric sorting (0.11.0)
Signed decimal sorting preserves precision with BigInt, including values beyond 2^53. It accepts correctly grouped commas, optional $/€/£/¥ symbols and Unicode minus. Empty or malformed numeric values and nonnumeric text fall back to text comparison. Compare one currency/unit per column; this is not a currency converter or locale parser. Sorting/filtering keep original row nodes and canonical markup intact.
Accessibility
- Table has standard semantic
<thead>and<tbody>structure - Checkboxes have
aria-labelfor accessibility - Sort icons rendered with
aria-sort="none"(values: none, ascending, descending, other, auto per ARIA 1.2)