Rendered by GPUI’s web backend from the real component. Requires a browser with WebGPU.
data_table.rs provides a working
client-side table composition. It uses the existing native Input/Field,
Table, ScrollArea, Checkbox, DropdownMenu, and Button, plus the InputGroup, EmptyState, and Pagination
recipes. The application supplies the columns and rows.
let state = cx.new(|cx| {
DataTableState::new(
[
DataTableColumn::new("Preset", px(180.)),
DataTableColumn::new("Description", px(280.)),
DataTableColumn::new("Bitrate", px(110.)).align_end(),
DataTableColumn::new("Updated", px(130.)),
],
rows, // DataTableRow::new(stable_id, [cells…]).disabled(false)
2, // Rows per page; must be positive.
window,
cx,
)
});
DataTable::new("preset-catalogue", &state, palette)
.accessibility_label("Recording presets")
.action_label("Use preset")
.selected_value(current_preset)
.on_action(move |id, window, cx| {
preset.update(cx, |state, cx| {
state.set_selected_values([id.as_ref()], window, cx);
});
})Keep the state entity in the application and observe it to redraw the parent.
Apply the application's InputEditorStyle to query_input(), as the two-style
example does. A row has a unique stable ID and one DataTableCell per column.
DataTableCell::text (or a plain string) sorts case-insensitively;
DataTableCell::number(display, value) and DataTableCell::date(display, date)
show formatted text such as $1,250.00 or Nov 2, 2026 but sort by value.
align_end right-aligns a column's heading and values, as for amounts. The
initial display order is the supplied row order. Header Buttons toggle one column
between ascending and descending order; equal keys retain their original order.
The native input owns the query. Every whitespace-separated term must appear in
the combined cell text, ignoring case. Matching/sorted indices are derived when
the query, sort or rows change. Changing the query or sort returns to the first page; moving focus
does not reset it. visible_rows(), filtered_count(), page_index(), and
page_count() expose the current view. set_page clamps to the available range,
and page/filter/sort changes return the row viewport to its vertical start.
The example derives its four rows from the same preset definitions used by the
Combobox, with an end-aligned numeric bitrate and a formatted update date. .selected_value supplies that Combobox's current value each render;
the table keeps no second selected value. A row action passes the stable ID to
the application even after filtering, sorting, or paging. Current and unavailable
rows have disabled action Buttons. The selected value remains in the application
when its row is filtered out or appears on another page.
Checkbox selection is independent of that current preset. The header checkbox
selects only enabled rows on the displayed page and shows a mixed state for a
partial selection. Selected stable IDs survive filtering, sorting, paging and
unmounting; unavailable rows cannot be selected. is_row_selected and
filtered_selected_count expose the selection. The footer counts selected rows
within the current filter, including other pages. Application row actions do not
change these checkboxes.
Columns opens a native checked menu. Toggle any data column, including all of
them; selection and action columns remain mounted. Hiding a column preserves
filtering, sorting, selection and pagination; filtering still searches its displayed text.
is_column_visible exposes each source column's visibility.
A table with no source rows shows No rows. If a filter hides every supplied row, the row viewport instead shows No matching rows and a Clear filter action. Clearing restores the rows and query focus without applying a row action. With results, focus follows query → Columns → page checkbox → visible sort Buttons → enabled row checkboxes/actions → enabled page Buttons. Horizontal and vertical ScrollArea scrolling reveals focused controls; there is no grid-style arrow navigation. Query, sort, and page survive unmounting the view while its state entity is retained.
Native Table indices describe the displayed page. TableRow::selected exposes
the checkbox selection. TableCell::sort_direction exposes the active native
column-header direction; body/footer cells ignore it. Header Button names also
announce the sorting description and next action.
Use DataTableColumn::render_cell(|row, text| ...) to supply a GPUI element.
The preset table renders the numeric bitrate as a Badge. The cell's text still supplies
its accessible name and filter terms, and its typed key still determines sort order.
Interactive children own their actions and can read row.is_disabled().
Call set_rows(new_rows, cx) to replace the data in the same state. The table reapplies
the current query and sort, preserves column visibility and keeps selections whose
IDs remain enabled. The page stays within the new bounds. set_page_size(size, cx)
accepts a positive size and keeps the former page's first row on the new page.
page_size() returns the current size.
Columns have fixed widths. Applications own remote data loading. Multi-column sorting, column reordering and virtualization remain outside this recipe.