Skip to main content

.table()

Adds a table.

TableOptions

.table({
preset?: "basic" | "minimal" | "striped",
columns: Column<T>[],
data: T[],
autoWidth?: "all" | "body" | false,
mergeSameValues?: boolean,
style?: TableStyle,
border?: BorderStyle,
conditionalStyle?: (row: T, col: keyof T) => CellStyle | {},
})
OptionTypeDefaultDescription
preset"basic" | "minimal" | "striped"-Preset style
columnsColumn<T>[]RequiredColumn definitions
dataT[]RequiredData array
autoWidth"all" | "body" | falsefalseAuto column width
mergeSameValuesbooleanfalseMerge cells with same values vertically
styleTableStyle-Table-wide style
borderBorderStyle-Border settings
conditionalStylefunction-Conditional styling

Column Definition (Column)

LeafColumn (Regular Column)

{
key: keyof T & string, // Data key
label: string, // Header text
style?: CellStyle, // Default style for this column
mergeSameValues?: boolean, // Merge same values in this column
}

ParentColumn (Multi-Header)

{
label: string, // Parent header text
children: Column<T>[], // Child columns (recursive)
}

Multi-header example:

columns: [
{
label: "Product Info",
children: [
{ key: "category", label: "Category" },
{ key: "name", label: "Name" },
],
},
{ key: "price", label: "Price" },
]

Result:

| Product Info       | Price |
| Category | Name | |

autoWidth

Auto-adjusts column width.

ValueDescription
"all"Adjust by max width of header and body
"body"Adjust by body only (ignore header)
falseNo auto-adjustment (default)
.table({
autoWidth: "all",
columns: [...],
data: [...],
})

mergeSameValues

Merges cells with same values vertically.

// Merge entire table
.table({
mergeSameValues: true,
columns: [...],
data: [...],
})

// Merge by column
.table({
columns: [
{ key: "category", label: "Category", mergeSameValues: true },
{ key: "name", label: "Name" },
],
data: [...],
})

conditionalStyle

Applies styles to cells based on conditions.

.table({
columns: [...],
data: [...],
conditionalStyle: (row, col) => {
if (col === "profit" && row.profit < 0) {
return { color: "#FF0000" };
}
return {};
},
})
  • Style API - CellStyle, TableStyle, BorderStyle details
  • Presets - Preset details