Browse documentation

Tables and data grids

Display many rows with virtualization, sorting, selection, and optional editing.

Import

Load the optional component layer before using the examples below.

Ruby
require "zaniah/ui"

Basic table

Columns use stable keys and optional labels, widths, sortability, editability, and rendering hooks.

Rendered example
A simple table and editable data grid beside a tree view.
Rendered by Zaniah's headless backend.
Ruby
rows = [{id: 1, name: "Ada"}, {id: 2, name: "Lin"}]
columns = [{key: :id, width: 54}, {key: :name, width: 140}]
Zaniah::UI::Table.new(rows, columns: columns,
  height: 190, row_key: ->(row) { row[:id] })

Editable grid

DataGrid shares the table model and adds editable cells. Use on_edit to own changes.

Ruby
Zaniah::UI::DataGrid.new(rows,
  columns: [{key: :name, editable: true}],
  height: 190, row_key: ->(row) { row[:id] })

Streaming and large data

VirtualTable queries source.count each frame and fetches only visible cells with source.cell(index, key). Optional row_id(index) preserves selection across reorder, row_style(index) supplies foreground/background/strikethrough, and index_of(id) speeds navigation after reorder. The application owns sorting through on_sort(key, direction, cx).

Ruby
Zaniah::UI::VirtualTable.new(source, columns: columns,
  row_height: 24, follow_tail: true)
  .on_select { |index, event, cx| inspect_record(index) }
  .on_sort { |key, direction, cx| source.sort(key, direction) }

Column changes and tail following

scroll_to(index, align:), resize_column(key, width), column_visible(key, bool), and move_column(key, index) update the view; on_columns_change receives the resulting columns. invalidate requests a fresh frame after asynchronous cell generation. Tail following pauses when the viewport leaves the bottom.

API summary

Constructor options and behaviors are drawn from the component reference.

ComponentConstructor and methodsVariants or behavior
VirtualTable(source, columns:, height:, row_height:, selection:, follow_tail:); lazy count/cell sourcestable row IDs, sortable/resizable headers, column visibility/order, row colors
Table, DataGrid(rows, columns:, height:, selection:, row_key:); on_sort, on_select, on_edit, on_copy, on_pastevirtual rows, sorting, resizing, editing, typed clipboard hooks

Accessibility

Rows and cells expose table semantics. Keyboard selection, sortable headers, and resize handles have distinct focus targets.

ComponentSemantic role
VirtualTabletable
Table, DataGridtable/row/cell