Slint · Slint components
This page shows the Slint implementation. Slint components written for native Rust applications and the browser. Browse the catalog, run each live example, and copy the .slint source into your own app.
Table
A simple, stateless, composable table component for rendering tabular data. Unlike DataTable, this component does not include virtual scrolling, sorting, or column management — it is designed for straightforward data display using a declarative API.
#Import
use gpui_kit::component::table::{
Table, TableHeader, TableBody, TableFooter,
TableRow, TableHead, TableCell, TableCaption,
};// Installed in ui/components. That directory is on the Slint include path, so import by file name:
import { Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption } from "table.slint";use iced::widget::{column, container, mouse_area, row, svg, text};
use iced::{Alignment, Element, Length, Task, Theme};import { signal, Text, View } from "nsh";
import { Avatar } from "./avatar";
import { Badge } from "./badge";
import { Button } from "./button";
import { Icon } from "./icon";
import { Input } from "./input";
import { Table, type TableColumn } from "./table";
import { tokens } from "./theme";#Usage
const usage = (
<Table
columns={invoiceColumns}
rows={invoices}
card
caption="A list of your recent invoices."
style={{ maxWidth: 560 }}
/>
);#Basic table
const basic = (
<Table columns={invoiceColumns} rows={invoices} card style={{ maxWidth: 560 }} />
);#Table with footer
const footer = (
<Table
columns={invoiceColumns}
rows={invoices}
footer={{ invoice: "Total", status: "", method: "", amount: "$750.00" }}
card
style={{ maxWidth: 560 }}
/>
);#Table in card with status badges
const taskColumns: TableColumn[] = [
{ key: "task", label: "Task" },
{ key: "status", label: "Status", align: "end", render: statusBadge },
];
const tasks = [
{ task: "Design homepage", status: "Completed" },
{ task: "Implement API", status: "In Progress" },
{ task: "Write tests", status: "Pending" },
];
const badges = (
<Table columns={taskColumns} rows={tasks} card style={{ maxWidth: 380 }} />
);#Table card with actions column
const actionColumns: TableColumn[] = [
{ key: "product", label: "Product" },
{ key: "price", label: "Price", align: "end" },
{
key: "actions",
label: "Actions",
align: "end",
render: () => (
<View style={{ alignItems: "flex-end" }}>
<Button icon="ellipsis" size="xsmall" variant="ghost" accessibilityLabel="Row actions" onPress={() => pressed.set("Actions opened")} />
</View>
),
},
];
const actions = (
<Table
columns={actionColumns}
rows={[
{ product: "Wireless Mouse", price: "$29.99" },
{ product: "Mechanical Keyboard", price: "$129.99" },
{ product: "USB-C Hub", price: "$49.99" },
]}
card
style={{ maxWidth: 420 }}
/>
);#Table with interactive elements
const interactiveColumns: TableColumn[] = [
{ key: "item", label: "Item" },
{
key: "quantity",
label: "Quantity",
render: () => <Input value={quantity()} onChangeText={(next) => quantity.set(next)} size="small" style={{ width: 52 }} />,
},
{ key: "price", label: "Price", align: "end" },
];
const interactive = (
<ColumnTable
columns={interactiveColumns}
rows={[
{ item: "Item Alpha", quantity: "1", price: "$10.00" },
{ item: "Item Beta", quantity: "2", price: "$20.00" },
{ item: "Item Gamma", quantity: "1", price: "$30.00" },
]}
/>
);#Team members table
const teamColumns: TableColumn[] = [
{ key: "member", label: "Member", width: 220, render: (_, row) => member(row.name, row.email) },
{ key: "role", label: "Role", width: 90, render: (value) => <Badge label={value} variant="secondary" /> },
{ key: "status", label: "Status", width: 74, render: statusBadge },
];
const team = (
<Table
columns={teamColumns}
rows={[
{ name: "Sarah Chen", email: "sarah@example.com", role: "Admin", status: "Active" },
{ name: "Marcus Johnson", email: "marcus@example.com", role: "Developer", status: "Active" },
{ name: "Emily Park", email: "emily@example.com", role: "Designer", status: "Away" },
{ name: "David Kim", email: "david@example.com", role: "Viewer", status: "Offline" },
]}
card
style={{ maxWidth: 440 }}
/>
);#Projects table
const projectColumns: TableColumn[] = [
{
key: "project",
label: "Project",
width: 230,
render: (_, row) => (
<View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
<Icon name="folder" size={13} color={tokens.mutedForeground} />
<View style={{ gap: 1 }}>
<Text style={{ fontSize: 11, fontWeight: "500", color: tokens.foreground }}>{row.project}</Text>
<Text style={{ fontSize: 9, color: tokens.mutedForeground }}>{row.description}</Text>
</View>
</View>
),
},
{ key: "status", label: "Status", width: 100, render: (value) => <Badge label={value} variant={value === "Completed" ? "success" : value === "Review" ? "warning" : "info"} /> },
{
key: "team",
label: "Team",
width: 120,
render: (_, row) => (
<View style={{ flexDirection: "row", alignItems: "center", gap: -4 }}>
{row.members.split(",").map((name) => (
<View style={{ marginEnd: -5 }}>
<Avatar name={name} size="xs" />
</View>
))}
<Text style={{ marginStart: 8, fontSize: 9, color: tokens.mutedForeground }}>{row.extra}</Text>
</View>
),
},
{ key: "due", label: "Due", width: 62, align: "end" },
];
const projects = (
<Table
columns={projectColumns}
rows={[
{ project: "Website Redesign", description: "Landing page and marketing site", status: "In Progress", members: "Sarah Chen,Marcus Johnson", extra: "+2", due: "Mar 15" },
{ project: "Mobile App v2", description: "iOS and Android release", status: "Review", members: "Emily Park,David Kim", extra: "", due: "Apr 1" },
{ project: "API Integration", description: "Third-party payment gateway", status: "Completed", members: "Sarah Chen", extra: "", due: "Feb 28" },
]}
card
style={{ maxWidth: 560 }}
/>
);#Activity log table
const activityColumns: TableColumn[] = [
{ key: "user", label: "User", width: 170, render: (_, row) => member(row.user, "Member") },
{ key: "action", label: "Action", width: 110, render: (value) => <Badge label={value} variant="outline" /> },
{ key: "target", label: "Target", width: 150, render: (value) => <Text style={{ fontSize: 10, fontFamily: "monospace", color: tokens.mutedForeground }} numberOfLines={1}>{value}</Text> },
{ key: "time", label: "Time", width: 100, align: "end" },
];
const activity = (
<Table
columns={activityColumns}
rows={[
{ user: "Sarah Chen", status: "Active", action: "Deployed", target: "production", time: "2 minutes ago" },
{ user: "Marcus Johnson", status: "Active", action: "Merged", target: "feat/auth-flow", time: "15 minutes ago" },
{ user: "Emily Park", status: "Away", action: "Commented", target: "PR #284", time: "1 hour ago" },
{ user: "David Kim", status: "Offline", action: "Reverted", target: "hotfix/api-crash", time: "3 hours ago" },
]}
card
style={{ maxWidth: 600 }}
/>
);#Subscription table
const serviceColumns: TableColumn[] = [
{ key: "service", label: "Service", render: (_, row) => <View style={{ gap: 1 }}><Text style={{ fontSize: 11, fontWeight: "500", color: tokens.foreground }}>{row.service}</Text><Text style={{ fontSize: 9, color: tokens.mutedForeground }}>{row.note}</Text></View> },
{ key: "plan", label: "Plan", render: (value) => <Badge label={value} variant="secondary" /> },
{ key: "billing", label: "Billing" },
{ key: "status", label: "Status", render: statusBadge },
{ key: "manage", label: "Actions", align: "end", render: () => <Button icon="settings" label="Manage" size="xsmall" variant="ghost" onPress={() => pressed.set("Manage subscription")} /> },
];
const services = (
<Table
columns={serviceColumns}
rows={[
{ service: "Vercel Pro", note: "Next: Mar 1, 2025", plan: "Pro", billing: "$20/mo", status: "Active" },
{ service: "GitHub Enterprise", note: "Next: Mar 10, 2025", plan: "Enterprise", billing: "$21/user/mo", status: "Active" },
{ service: "Figma Organization", note: "Next: Apr 5, 2025", plan: "Organization", billing: "$45/editor/mo", status: "Active" },
{ service: "Slack Business+", note: "Next: —", plan: "Business+", billing: "$12.50/user/mo", status: "Cancelled" },
]}
card
style={{ maxWidth: 620 }}
/>
);#Inventory table
const inventoryColumns: TableColumn[] = [
{ key: "product", label: "Product", width: 210, render: (_, row) => <View style={{ flexDirection: "row", alignItems: "center", gap: 6, minWidth: 0 }}><View style={{ width: 22, height: 22, borderRadius: 6, backgroundColor: tokens.muted, alignItems: "center", justifyContent: "center" }}><Icon name="package" size={12} color={tokens.mutedForeground} /></View><View style={{ gap: 1 }}><Text style={{ fontSize: 11, fontWeight: "500", color: tokens.foreground }}>{row.product}</Text><Text style={{ fontSize: 9, color: tokens.mutedForeground }}>{row.sku}</Text></View></View> },
{ key: "category", label: "Category", width: 84 },
{ key: "stock", label: "Stock", width: 112, render: (_, row) => <View style={{ flexDirection: "row", alignItems: "center", gap: 4 }}>{statusBadge(row.stock)}{row.count ? <Text style={{ fontSize: 9, color: tokens.mutedForeground }}>({row.count})</Text> : null}</View> },
{ key: "price", label: "Price", width: 76, align: "end" },
{ key: "actions", label: "", width: 28, align: "end", render: () => <Button icon="ellipsis" size="xsmall" variant="ghost" accessibilityLabel="Actions" onPress={() => {}} /> },
];
const inventory = (
<Table
columns={inventoryColumns}
rows={[
{ product: "Ergonomic Desk Chair", sku: "FRN-001", category: "Furniture", stock: "In Stock", count: "124", price: "$549.00" },
{ product: "Wireless Headphones", sku: "AUD-012", category: "Audio", stock: "Low Stock", count: "8", price: "$349.99" },
{ product: "4K Ultra HD Monitor", sku: "DSP-019", category: "Displays", stock: "Out of Stock", count: "0", price: "$799.00" },
{ product: "Mechanical Keyboard RGB", sku: "INP-087", category: "Input", stock: "In Stock", count: "56", price: "$179.99" },
]}
card
style={{ maxWidth: 620 }}
/>
);#API keys table
const keyColumns: TableColumn[] = [
{ key: "name", label: "Name", width: 170, render: (_, row) => <View style={{ gap: 1 }}><Text style={{ fontSize: 11, fontWeight: "500", color: tokens.foreground }}>{row.name}</Text><Text style={{ fontSize: 9, color: tokens.mutedForeground }}>{row.used}</Text></View> },
{ key: "key", label: "Key", width: 150, render: (value) => <Text style={{ fontSize: 10, fontFamily: "monospace", color: tokens.mutedForeground }}>{value}</Text> },
{ key: "permissions", label: "Permissions", width: 150, render: (_, row) => <View style={{ flexDirection: "row", gap: 3 }}>{row.permissions.split(",").map((item) => <Badge label={item} variant="outline" />)}</View> },
{ key: "status", label: "Status", width: 70, render: statusBadge },
{ key: "actions", label: "", width: 40, align: "end", render: () => <View style={{ flexDirection: "row", justifyContent: "flex-end", gap: 2 }}><Button icon="copy" size="xsmall" variant="ghost" accessibilityLabel="Copy key" onPress={() => {}} /><Button icon="refresh-cw" size="xsmall" variant="ghost" accessibilityLabel="Regenerate key" onPress={() => {}} /></View> },
];
const keys = (
<Table
columns={keyColumns}
rows={[
{ name: "Production API", used: "Last used: 2 minutes ago", key: "sk_live_••••••••4f3a", permissions: "read,write", status: "Active" },
{ name: "Staging API", used: "Last used: 1 hour ago", key: "sk_test_••••••••8b2c", permissions: "read,write,admin", status: "Active" },
{ name: "CI/CD Pipeline", used: "Last used: 3 days ago", key: "sk_ci_••••••••1d9e", permissions: "read", status: "Active" },
{ name: "Legacy Integration", used: "Last used: 30 days ago", key: "sk_old_••••••••7a5f", permissions: "read,write", status: "Expired" },
]}
card
style={{ maxWidth: 680 }}
/>
);#Files table
const fileColumns: TableColumn[] = [
{ key: "name", label: "Name", width: 230, render: (_, row) => <View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}><Icon name={row.kind === "folder" ? "folder" : "file-text"} size={13} color={tokens.mutedForeground} /><Text style={{ fontSize: 11, color: tokens.foreground }}>{row.name}</Text></View> },
{ key: "owner", label: "Owner", width: 130, render: (value) => <View style={{ flexDirection: "row", alignItems: "center", gap: 4 }}><Avatar name={value} size="xs" /><Text style={{ fontSize: 10, color: tokens.foreground }}>{value}</Text></View> },
{ key: "sharing", label: "Sharing", width: 76, render: (value) => <Badge label={value} variant="secondary" /> },
{ key: "size", label: "Size", width: 70, align: "end" },
{ key: "modified", label: "Modified", width: 100, align: "end" },
];
const files = (
<Table
columns={fileColumns}
rows={[
{ kind: "file", name: "Q4 Financial Report.pdf", owner: "Sarah Chen", sharing: "Team", size: "2.4 MB", modified: "2 hours ago" },
{ kind: "folder", name: "Brand Guidelines", owner: "Emily Park", sharing: "Public", size: "—", modified: "1 day ago" },
{ kind: "file", name: "Product Roadmap 2025.xlsx", owner: "Marcus Johnson", sharing: "Private", size: "856 KB", modified: "3 days ago" },
{ kind: "folder", name: "App Screenshots", owner: "David Kim", sharing: "Team", size: "48.2 MB", modified: "1 week ago" },
]}
card
style={{ maxWidth: 700 }}
/>
);#Issues table
const issueColumns: TableColumn[] = [
{ key: "id", label: "ID", width: 56, render: (value) => <Text style={{ fontSize: 9, fontFamily: "monospace", color: tokens.mutedForeground }}>{value}</Text> },
{ key: "issue", label: "Issue", width: 220, render: (_, row) => <View style={{ gap: 1 }}><Text style={{ fontSize: 11, fontWeight: "500", color: tokens.foreground }}>{row.issue}</Text><Badge label={row.label} variant="outline" /></View> },
{ key: "assignee", label: "Assignee", width: 120, render: (value) => <View style={{ flexDirection: "row", alignItems: "center", gap: 4 }}><Avatar name={value} size="xs" /><Text style={{ fontSize: 10, color: tokens.foreground }}>{value}</Text></View> },
{ key: "status", label: "Status", width: 90, render: statusBadge },
];
const issues = (
<Table
columns={issueColumns}
rows={[
{ id: "ISS-421", issue: "Login page returns 500 on mobile", label: "Bug", assignee: "Sarah Chen", status: "In Progress" },
{ id: "ISS-420", issue: "Add dark mode support", label: "Feature", assignee: "Marcus Johnson", status: "In Review" },
{ id: "ISS-419", issue: "Update user onboarding flow", label: "Improvement", assignee: "Emily Park", status: "Open" },
{ id: "ISS-418", issue: "Refactor API rate limiter module", label: "Tech Debt", assignee: "David Kim", status: "Completed" },
]}
card
style={{ maxWidth: 600 }}
/>
);#Leaderboard table
const leaderColumns: TableColumn[] = [
{ key: "rank", label: "#", width: 24, render: (value) => <Text style={{ fontSize: 10, color: tokens.mutedForeground }}>{value}</Text> },
{ key: "player", label: "Player", render: (_, row) => <View style={{ flexDirection: "row", alignItems: "center", gap: 5 }}><Avatar name={row.player} size="xs" /><View style={{ gap: 1 }}><Text style={{ fontSize: 11, fontWeight: "500", color: tokens.foreground }}>{row.player}</Text><Text style={{ fontSize: 9, color: tokens.mutedForeground }}>{row.handle}</Text></View></View> },
{ key: "level", label: "Level", render: (value) => <Badge label={value} variant="secondary" /> },
{ key: "score", label: "Score", align: "end", render: (value) => <Text style={{ fontSize: 11, textAlign: "right", color: tokens.foreground }}>{value}</Text> },
{ key: "change", label: "Change", align: "end", render: (value) => <Text style={{ fontSize: 10, textAlign: "right", color: value.startsWith("+") ? tokens.success : tokens.danger }}>{value}</Text> },
];
const leaderboard = (
<Table
columns={leaderColumns}
rows={[
{ rank: "1", player: "Sarah Chen", handle: "@sarahchen", level: "Diamond", score: "12,840", change: "+320" },
{ rank: "2", player: "Marcus Johnson", handle: "@marcus", level: "Platinum", score: "11,250", change: "+180" },
{ rank: "3", player: "Emily Park", handle: "@emilyp", level: "Platinum", score: "10,890", change: "-45" },
{ rank: "4", player: "David Kim", handle: "@davidk", level: "Gold", score: "9,420", change: "+520" },
{ rank: "5", player: "Sofia Davis", handle: "@sofia", level: "Gold", score: "8,750", change: "+90" },
]}
card
style={{ maxWidth: 600 }}
/>
);#Vertical profile table
const profile = (
<View style={{ maxWidth: 440 }}>
<Table
columns={[
{ key: "field", label: "", width: 110 },
{
key: "value",
label: "",
render: (value, row) =>
row.field === "Employee" ? (
<View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}><Avatar name={value} size="sm" /><View style={{ gap: 1 }}><Text style={{ fontSize: 11, fontWeight: "500", color: tokens.foreground }}>{value}</Text><Text style={{ fontSize: 9, color: tokens.mutedForeground }}>Lead Product Designer</Text></View></View>
) : row.field === "Status" ? (
statusBadge(value)
) : (
<Text style={{ fontSize: 11, color: tokens.foreground }}>{value}</Text>
),
},
]}
rows={[
{ field: "Employee", value: "Sarah Chen" },
{ field: "Department", value: "Design & User Experience" },
{ field: "Email", value: "sarah.chen@acmecorp.com" },
{ field: "Location", value: "San Francisco, CA" },
{ field: "Status", value: "Active" },
{ field: "Start Date", value: "March 15, 2022" },
{ field: "Reports To", value: "James Rodriguez, VP of Design" },
]}
card
/>
</View>
);#Server status table
Table::new()
.child(TableHeader::new().child(
TableRow::new()
.child(TableHead::new().child("Name"))
.child(TableHead::new().child("Email"))
.child(TableHead::new().text_right().child("Amount"))
))
.child(TableBody::new()
.child(TableRow::new()
.child(TableCell::new().child("John"))
.child(TableCell::new().child("john@example.com"))
.child(TableCell::new().text_right().child("$100.00")))
.child(TableRow::new()
.child(TableCell::new().child("Jane"))
.child(TableCell::new().child("jane@example.com"))
.child(TableCell::new().text_right().child("$200.00")))
)
.child(TableCaption::new().child("A list of recent invoices."))Table {
TableHeader {
TableRow {
TableHead {
text: "Invoice";
}
TableHead {
text: "Status";
}
TableHead {
text: "Method";
}
TableHead {
text: "Amount";
align: TextHorizontalAlignment.right;
}
}
}
TableBody {
for row[
i
]
in invoices: TableRow {
index: i;
TableCell {
text: row.invoice;
}
TableCell {
text: row.status;
}
TableCell {
text: row.method;
}
TableCell {
text: row.amount;
align: TextHorizontalAlignment.right;
}
}
}
TableCaption {
text: "A list of your recent invoices.";
}
}// The header band, twelve rows in a bounded scroll area, and the caption.
// Slint stacks the rows and lets the page scroll; this port puts the body on
// `scrollable`, so the header and the caption stay while the rows move. The
// `index` on each row is what draws the rule above it.
let mut basic_rows = Vec::new();
for (index, (invoice, status, method, amount)) in INVOICES.iter().enumerate() {
basic_rows.push(invoice_row(
index,
invoice,
status,
method,
amount,
ControlSize::Medium,
false,
));
}
let basic = Table::new()
.header(TableHeader::new().row(
TableRow::new()
.head("Invoice")
.head("Status")
.head("Method")
.head(TableHead::new("Amount").align(Align::End)),
))
.body(TableBody::new(basic_rows).height(Length::Fixed(BODY_HEIGHT)))
.caption("A list of your recent invoices.");const server = (
<View style={{ maxWidth: 440 }}>
<Table
columns={[
{ key: "field", label: "Droplet Status", width: 120, render: (value) => <Text style={{ fontSize: 10, color: tokens.mutedForeground }}>{value}</Text> },
{
key: "value",
label: "Primary production server",
render: (value, row) =>
row.field === "Status" ? (
<View style={{ flexDirection: "row", alignItems: "center", gap: 4 }}><View style={{ width: 6, height: 6, borderRadius: 3, backgroundColor: tokens.success }} /><Text style={{ fontSize: 11, color: tokens.success }}>{value}</Text></View>
) : /(\d+)%/.test(value) ? (
<View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}><View style={{ width: 60, height: 4, borderRadius: 2, backgroundColor: tokens.muted }}><View style={{ width: Number(value.replace("%", "")) || 0, height: "100%", borderRadius: 2, backgroundColor: tokens.warning }} /></View><Text style={{ fontSize: 10, color: tokens.foreground }}>{value}</Text></View>
) : (
<Text style={{ fontSize: 11, color: tokens.foreground }}>{value}</Text>
),
},
]}
rows={[
{ field: "Status", value: "Operational" },
{ field: "Instance Type", value: "c6g.2xlarge" },
{ field: "Region", value: "US East (N. Virginia)" },
{ field: "CPU Usage", value: "42%" },
{ field: "Memory", value: "10.7 / 16 GB" },
{ field: "Uptime", value: "47 days, 12 hours" },
{ field: "OS", value: "Amazon Linux 2023" },
{ field: "Tags", value: "production · api · critical" },
]}
card
/>
</View>
);#Striped, bordered and sizes
Table::new()
.child(TableHeader::new().child(
TableRow::new()
.child(TableHead::new().child("Invoice"))
.child(TableHead::new().child("Status"))
.child(TableHead::new().text_right().child("Amount"))
))
.child(TableBody::new()
.child(TableRow::new()
.child(TableCell::new().child("INV001"))
.child(TableCell::new().child("Paid"))
.child(TableCell::new().text_right().child("$250.00")))
)
.child(TableFooter::new().child(
TableRow::new()
.child(TableCell::new().child("Total"))
.child(TableCell::new().child(""))
.child(TableCell::new().text_right().child("$250.00"))
))GridLayout {
spacing: 8px;
Button {
horizontal-stretch: 0;
text: "Striped";
selected: striped;
clicked => {
striped = !striped;
}
}
Button {
horizontal-stretch: 0;
text: "Bordered";
selected: bordered;
clicked => {
bordered = !bordered;
}
}
Rectangle {
horizontal-stretch: 0;
width: 8px;
}
Button {
horizontal-stretch: 0;
text: "Small";
selected: table-size == ControlSize.small;
clicked => {
table-size = ControlSize.small;
}
}
Button {
horizontal-stretch: 0;
text: "Medium";
selected: table-size == ControlSize.medium;
clicked => {
table-size = ControlSize.medium;
}
}
Button {
horizontal-stretch: 0;
text: "Large";
selected: table-size == ControlSize.large;
clicked => {
table-size = ControlSize.large;
}
}
}
Table {
bordered: bordered;
TableHeader {
TableRow {
TableHead {
text: "Invoice";
size: table-size;
}
TableHead {
text: "Status";
size: table-size;
align: TextHorizontalAlignment.center;
}
TableHead {
text: "Method";
size: table-size;
}
TableHead {
text: "Amount";
size: table-size;
align: TextHorizontalAlignment.right;
}
}
}
TableBody {
for row[
i
]
in invoices: TableRow {
index: i;
striped: striped;
TableCell {
text: row.invoice;
size: table-size;
}
TableCell {
size: table-size;
align: TextHorizontalAlignment.center;
VerticalLayout {
alignment: center;
Rectangle {
property <color> tone: row.status == "Paid" ? Theme.success : row.status == "Pending" ? Theme.warning : Theme.danger;
height: 20px;
border-radius: Theme.radius-sm;
background: Theme.tint(tone);
HorizontalLayout {
padding-left: 6px;
padding-right: 6px;
Text {
text: row.status;
color: tone;
font-size: Theme.font-size-xs;
font-weight: 500;
vertical-alignment: center;
}
}
}
}
}
TableCell {
text: row.method;
size: table-size;
}
TableCell {
text: row.amount;
size: table-size;
align: TextHorizontalAlignment.right;
}
}
}
TableFooter {
TableRow {
TableCell {
text: "Total";
size: table-size;
col-span: 3;
}
TableCell {
text: "$1,750.00";
size: table-size;
align: TextHorizontalAlignment.right;
}
}
}
}// The three switches the Slint example puts above its table. Only what the
// caller changes is state: the table itself reads the switch back.
let controls = row![
Button::new("Striped")
.selected(app.striped)
.on_press(Message::ToggleStriped),
Button::new("Bordered")
.selected(app.bordered)
.on_press(Message::ToggleBordered),
Button::new("Small")
.selected(app.size == ControlSize::Small)
.on_press(Message::SetSize(ControlSize::Small)),
Button::new("Medium")
.selected(app.size == ControlSize::Medium)
.on_press(Message::SetSize(ControlSize::Medium)),
Button::new("Large")
.selected(app.size == ControlSize::Large)
.on_press(Message::SetSize(ControlSize::Large)),
]
.spacing(theme::SPACING_SM);
let mut striped_rows = Vec::new();
for (index, (invoice, status, method, amount)) in INVOICES.iter().take(5).enumerate() {
striped_rows.push(
invoice_row(
index,
invoice,
status,
method,
amount,
app.size,
true,
)
.striped(app.striped),
);
}
let striped = Table::new()
.bordered(app.bordered)
.header(TableHeader::new().row(
TableRow::new()
.head(TableHead::new("Invoice").size(app.size))
.head(TableHead::new("Status").size(app.size).align(Align::Center))
.head(TableHead::new("Method").size(app.size))
.head(TableHead::new("Amount").size(app.size).align(Align::End)),
))
.body(TableBody::new(striped_rows))
.footer(TableFooter::new().row(
TableRow::new()
.cell(TableCell::new("Total").span(3).size(app.size))
.cell(
TableCell::new("$1,750.00")
.align(Align::End)
.size(app.size),
),
));#Column widths
// A width on the head and the cell of a column pins it, and the columns
// without one share what is left. Slint expresses the same thing with
// `width` and leaves the rest at its preferred width.
let widths = Table::new()
.header(TableHeader::new().row(
TableRow::new()
.head(TableHead::new("ID").width(80.0))
.head("Name")
.head(TableHead::new("Date").width(120.0)),
))
.body(TableBody::new([
TableRow::new()
.index(0)
.cell(TableCell::new("INV-0042").mono(true).width(80.0))
.cell("Northwind Trading")
.cell(TableCell::new("2026-11-10").width(120.0)),
TableRow::new()
.index(1)
.cell(TableCell::new("INV-0041").mono(true).width(80.0))
.cell("Contoso Ltd")
.cell(TableCell::new("2026-11-09").width(120.0)),
]));Use .w() on TableHead and TableCell to set fixed column widths:
TableRow::new()
.child(TableHead::new().w(px(80.)).child("ID"))
.child(TableHead::new().child("Name")) // flex-1
.child(TableHead::new().w(px(120.)).child("Date"))#Text Alignment
// Center-aligned header
TableHead::new().text_center().child("Status")
// Right-aligned cell (e.g., for numbers)
TableCell::new().text_right().child("$1,000.00")// A center-aligned header and an end-aligned number, the two alignments a
// table needs beyond the default start.
let alignment = Table::new()
.header(TableHeader::new().row(
TableRow::new()
.head("Item")
.head(TableHead::new("Status").align(Align::Center))
.head(TableHead::new("Amount").align(Align::End)),
))
.body(TableBody::new([
TableRow::new()
.index(0)
.cell("Team plan")
.cell(TableCell::new("Active").align(Align::Center))
.cell(TableCell::new("$250.00").align(Align::End).mono(true)),
TableRow::new()
.index(1)
.cell("Seats")
.cell(TableCell::new("12").align(Align::Center))
.cell(TableCell::new("$60.00").align(Align::End).mono(true)),
]));#Without Border (via Styled)
// GPUI drops the edge with `.border_0().rounded_none()`. iced has no `Styled`
// trait, so the component carries the switch: `bordered(false)` keeps the
// fill and the bands and removes the edge and the corners.
let plain = Table::new()
.bordered(false)
.header(TableHeader::new().row(
TableRow::new()
.head("Method")
.head(TableHead::new("Amount").align(Align::End)),
))
.body(TableBody::new([
TableRow::new()
.index(0)
.cell("Credit Card")
.cell(TableCell::new("$250.00").align(Align::End).mono(true)),
TableRow::new()
.index(1)
.cell("PayPal")
.cell(TableCell::new("$150.00").align(Align::End).mono(true)),
]));All table sub-components implement the Styled trait, so you can customize styles directly:
// Remove border and rounded corners
Table::new()
.border_0()
.rounded_none()
.child(/* ... */)#Custom Styling
Since all components implement Styled, you can apply any GPUI style:
// Custom row hover
TableRow::new()
.bg(cx.theme().table_even)
.child(/* ... */)
// Custom cell padding
TableCell::new()
.px_4()
.child("Custom padded content")#Sub-components
| Component | Description |
|---|---|
Table | Root container with border, rounded corners, and background |
TableHeader | Header section with distinct background and font weight |
TableBody | Body section wrapping data rows |
TableFooter | Footer section with top border |
TableRow | A flex row with bottom border |
TableHead | Header cell with alignment and width options |
TableCell | Data cell with alignment and width options |
TableCaption | Caption text below the table |
#Table vs DataTable
| Feature | Table | DataTable |
|---|---|---|
| Virtual scrolling | No | Yes |
| Column sorting | No | Yes |
| Column resizing | No | Yes |
| Column moving | No | Yes |
| Cell selection | No | Yes |
| Row selection | No | Yes |
| Infinite loading | No | Yes |
| Keyboard navigation | No | Yes |
| State management | Stateless | TableState |
| Best for | Small, static data | Large, interactive datasets |
#API Reference
#Table
new()- Create a new table- Implements
Styled,ParentElement,Sizable,RenderOnce
#TableHead / TableCell
new()- Create a new head/cellw(width)- Set fixed width (otherwise flex-1)text_center()- Center-align contenttext_right()- Right-align content- Implements
Styled,ParentElement,RenderOnce
#TableHeader / TableBody / TableFooter / TableRow / TableCaption
new()- Create a new instance- Implements
Styled,ParentElement,RenderOnce
#Table
A static table. Mirrors GPUI Component's `Table`: a bordered, rounded surface that stacks a `TableHeader`, a `TableBody`, an optional `TableFooter` and a `TableCaption`. Rows are `TableRow`s of `TableHead` or `TableCell`; cells share the row width equally (100px minimum) unless given an explicit `width`, and align their content with `align`. Set `index` on body rows so they draw the row separator, and `striped` for alternating backgrounds. `bordered: false` removes the outer border and radius.
| Name | Kind | Type | Default |
|---|---|---|---|
bordered | in | bool | true |
#TableHeader
The header section of a `Table`: a muted band with a bottom separator.
#TableBody
The body section of a `Table`, wrapping data rows.
#TableFooter
The footer section of a `Table`: a muted band with a top separator.
#TableRow
A row of a `Table`. Rows after the first (`index > 0`) draw a top separator; with `striped`, odd rows get the even-row background.
| Name | Kind | Type | Default |
|---|---|---|---|
index | in | int | |
striped | in | bool |
#TableHead
A header cell. Shows `text` in the muted header style, or custom children.
| Name | Kind | Type | Default |
|---|---|---|---|
text | in | string | |
align | in | TextHorizontalAlignment | TextHorizontalAlignment.left |
size | in | ControlSize | ControlSize.medium |
col-span | in | int | 1 |
#TableCell
A data cell. Shows `text`, or custom children (badges, icons, buttons).
| Name | Kind | Type | Default |
|---|---|---|---|
text | in | string | |
align | in | TextHorizontalAlignment | TextHorizontalAlignment.left |
size | in | ControlSize | ControlSize.medium |
col-span | in | int | 1 |
text-color | in | color | Theme.foreground |
mono | in | bool |
#TableCaption
A caption below the table body, centered in the muted style.
| Name | Kind | Type | Default |
|---|---|---|---|
text | in | string | |
size | in | ControlSize | ControlSize.medium |