Table
ui.widgets.Table固定列定义与自定义 cell renderer 的基础表格。
BEHAVIOR CONTRACT
列宽、header、striped row、排序入口和 cell 生命周期清晰分离。
RECORDED INTERACTION
录像展示真实 8 行数据和 sortable 列。
pub fn buildTable(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
const cols = [_]W.ColumnDef{
.{ .id = "name", .header = "Name", .width = 160 },
.{ .id = "role", .header = "Role", .width = 120 },
.{ .id = "age", .header = "Age", .width = 80, .sortable = true },
};
const t = try W.Table(.{ .columns = &cols, .row_count = 8, .striped = true, .render_cell = tableCell }).mount(scope, cx);
return t.wrapper;
}这是 Storybook 中该 story 的原样代码(zenit 5f9add5+wip 2026-09-30)。其中 W 即 ui.widgets,col / row / label 是 Storybook 内的布局小工具。
TableProps
ui.widgets.Tablefn Table(props: TableProps) TableBuilder字段
类型
默认值
说明
columns[]const ColumnDef&.{}—
row_countusize0—
row_heightf3236—
header_heightf3240—
stripedboolfalse—
hoverablebooltrue—
table_width?f32null—
table_heightf32400—
render_cell?CellRenderFnnull—
on_sort?core.HandlerRefnull—
on_row_click?core.HandlerRefnull—
TableResult
ui.widgets.Table字段
类型
默认值
说明
wrapper*Node—
—
state*TableState—
—
vl_state?*VirtualListStatenull虚拟滚动模式下的 VirtualListState(可用于动态更新 row_count)