Table
A table with the columns columns and rows rows.
ui.tableBasic
let columns = [ TableColumn::new("File"), TableColumn::new("Type"), TableColumn::new("Size").w(84),];ui.table(&columns, 50).h(130).show(|row, i| { row.text(format_args!("report-{i:02}.pdf")); row.text("PDF").muted(); row.text(format_args!("{} KB", 120 + i * 7)).mono();});Single selection
let columns = [TableColumn::new("File"), TableColumn::new("Size").w(84)];// A click or the arrow keys choose a row.ui.table(&columns, 50).h(130).selected(&mut self.row).show(|row, i| { row.text(format_args!("report-{i:02}.pdf")); row.text(format_args!("{} KB", 120 + i * 7)).mono();});Multiple selection
let columns = [TableColumn::new("File"), TableColumn::new("Size").w(84)];// Command or Shift with a click adds rows.ui.table(&columns, 50).h(130).selection(&mut self.rows).show(|row, i| { row.text(format_args!("report-{i:02}.pdf")); row.text(format_args!("{} KB", 120 + i * 7)).mono();});Sorting
let columns = [ TableColumn::new("File").sortable(), TableColumn::new("Size").w(84).sortable(),];// The table shows the sort; the application orders its rows.let descending = self.sort.is_some_and(|s| s.direction == SortDirection::Descending);ui.table(&columns, 50).h(130).sort(&mut self.sort).show(|row, i| { let i = if descending { 49 - i } else { i }; row.text(format_args!("report-{i:02}.pdf")); row.text(format_args!("{} KB", 120 + i * 7)).mono();});Resizable columns
let columns = [ TableColumn::new("File").w(200).resizable(), TableColumn::new("Type").w(80).resizable(), TableColumn::new("Size"),];// Drag the edge of a header; keep `widths` to restore them later.ui.table(&columns, 50).h(130).column_widths(&mut self.widths).show(|row, i| { row.text(format_args!("report-{i:02}.pdf")); row.text("PDF").muted(); row.text(format_args!("{} KB", 120 + i * 7)).mono();});Column alignment
let columns = [ TableColumn::new("Start"), TableColumn::new("Center").align(Align::Center), TableColumn::new("End").align(Align::End),];ui.table(&columns, 3).h(130).show(|row, i| { row.text(format_args!("Row {i}")); row.text("PDF").muted(); row.text(format_args!("{} KB", 120 + i * 7)).mono();});Row height
let columns = [TableColumn::new("File"), TableColumn::new("Size").w(84)];ui.table(&columns, 50).row_height(24).h(130).show(|row, i| { row.text(format_args!("report-{i:02}.pdf")).text_sm(); row.text(format_args!("{} KB", 120 + i * 7)).text_sm().mono();});Cells with any widget
let columns = [TableColumn::new("File"), TableColumn::new("State").w(100)];ui.table(&columns, 3).h(130).show(|row, i| { row.cell(|ui| { ui.row().gap(8).children(|ui| { ui.icon(IconName::File); ui.text(format_args!("report-{i:02}.pdf")); }); }); row.cell(|ui| { ui.badge("Synced").success(); });});API reference
| Setting | Description |
|---|---|
.row_height(row_height: impl Length) | The row height in logical pixels. |
.h(height: impl Into<Sizing>) | The height including the header; a plain length is a fixed height. By default the table is as tall as its rows, up to 240 logical pixels, and scrolls beyond that. |
.h_fill() | Takes the remaining height. |
.selected(row: &'u mut Option<usize>) | Binds the selected row, which is highlighted. |
.selection(rows: &'u mut BTreeSet<usize>) | Allows selecting several rows, bound to rows. |
.column_widths(widths: &'u mut Vec<f32>) | Binds the widths of resizable columns, to keep them. |
.sort(sort: &'u mut Option<Sort>) | Binds the sort; None means unsorted. |
.show(row: impl FnMut(&mut TableRow<'_, 'a>, usize)) | Places the table. |