GPUI Box GitHub

Components / data

Table builder

A table with a header that stays put while the body scrolls.

A builder is RenderOnce. Construct and mount it in one expression.

use gpui_kit::data::Table;

Reviewed in table.

Construct
new(ident: impl Into<Ident>) -> Self
Options

Chain onto the value.

column(column: Column) -> Self
columns(columns: impl IntoIterator<Item = Column>) -> Self
rows(rows: impl IntoIterator<Item = Row>) -> Self
rows_from(count: usize, render_row: impl Fn(usize, &mut Window, &mut App) -> Row + 'static) -> Self
sort(sort: Option<(SharedString, SortDirection)>) -> Self
sorted_by(key: impl Into<SharedString>, direction: SortDirection) -> Self
selected(id: impl Into<SharedString>) -> Self
row_height(height: f32) -> Self
visible_rows(rows: usize) -> Self
lines(lines: GridLines) -> Self
loading(loading: bool) -> Self
failure(failure: impl Into<SharedString>) -> Self
empty(empty: EmptyState) -> Self
on_sort(handler: impl Fn(SharedString, SortDirection, &mut Window, &mut App) + 'static) -> Self
on_select(handler: impl Fn(SharedString, &mut Window, &mut App) + 'static) -> Self
Example · table
fn table(_window: &mut Window, cx: &mut App) -> AnyElement {
    let theme = cx.theme().clone();
    let state = |label: &'static str, tone: Tone| {
        Cell::new(Badge::new(label).tone(tone))
            .text(label)
            .published(true)
    };
    let columns = [
        Column::new("name", "Run").flex(2.0).sortable(true),
        Column::new("state", "State").fixed(110.0),
        Column::new("duration", "Duration")
            .fixed(96.0)
            .align(Align::End)
            .sortable(true),
    ];
    stack(&theme)
        .w(px(600.0))
        .child(
            Table::new("scene.table.runs")
                .columns(columns.clone())
                .sorted_by("duration", SortDirection::Descending)
                .selected("run-b12")
                .rows([
                    Row::new("run-a04")
                        .text("Indexing")
                        .cell("name", "Indexing")
                        .cell("state", state("Ready", Tone::Success))
                        .cell("duration", "4m 12s"),
                    Row::new("run-b12")
                        .text("Verifying")
                        .cell("name", "Verifying")
                        .cell("state", state("Stale", Tone::Warning))
                        .cell("duration", "2m 08s"),
                    Row::new("run-c31")
                        .text("Publishing")
                        .cell("name", "Publishing")
                        .cell("state", state("Refused", Tone::Danger))
                        .cell("duration", "1m 44s"),
                    Row::new("run-d02")
                        .text("Archiving")
                        .disabled(true)
                        .cell("name", "Archiving")
                        .cell("state", state("Managed", Tone::Neutral))
                        .cell("duration", "0m 51s"),
                ])
                .visible_rows(6)
                .on_sort(|_, _, _, _| {})
                .on_select(|_, _, _| {}),
        )
        .child(
            Table::new("scene.table.stale")
                .columns(columns.clone())
                .rows([Row::new("run-a04")
                    .text("Indexing")
                    .cell("name", "Indexing")
                    .cell("state", state("Ready", Tone::Success))
                    .cell("duration", "4m 12s")])
                .failure("The host refused the refresh")
                .on_select(|_, _, _| {}),
        )
        .child(
            Table::new("scene.table.empty")
                .columns(columns)
                .on_select(|_, _, _| {}),
        )
        .into_any_element()
}

Source: crates/gpui-kit/src/data/table.rs