Skip to content

API Quick Reference

A condensed reference for all public classes, methods, and options.

Table

The core class. Holds columns, rows, and rendering configuration.

Constructor

ts
new Table(options?: TableOptions)
OptionTypeDefaultDescription
columnsColumnConfig[][]Column definitions
themeIThemeTHEME_RoundedBorder theme
headerColorColorName'magenta'Header text color
compactbooleanfalseRemove row separators
zebrabooleanfalseDim alternating rows
responsiveMode'none' | 'hide' | 'stack''none'Responsive behavior
terminalWidthnumberautoOverride terminal width
headerGroupsHeaderGroup[][]Column grouping headers

Methods

MethodReturnsDescription
addColumn(config)voidAdd a column (string or config object)
setColumns(configs)voidReplace all columns
addRow(data)voidAdd a row (object, array, or cell array)
addRows(data[])voidAdd multiple rows
render()stringRender the table to a string
sort(column, dir?)voidSort rows by column ('asc' or 'desc')
paginate(pageSize)voidSlice rows to first page
getPages(pageSize)Table[]Split into page-sized Table instances
export(format)stringExport to 'md', 'csv', 'json', or 'html'
summarize(cols, algo)voidCompute footer ('sum', 'avg', 'count')
setFooter(data)voidSet a custom footer row
addTree(col, data)voidAdd hierarchical tree data
mergeAdjacent(cols?)voidVertically merge identical adjacent cells

Static Methods

MethodReturnsDescription
Table.fromVertical(data)TableCreate from vertical key-value pairs
Table.fromCross(data, opts)TableCreate from CrossTab results

Properties

PropertyTypeDescription
columnsColumn[]Array of column definitions
rowsRow[]Array of row objects
footerany[] | RecordFooter row data
themeIThemeCurrent theme

Column

Column configuration options:

OptionTypeDefaultDescription
namestringDisplay name
keystringnameData lookup key
widthnumberautoFixed width
minWidthnumberMinimum width
maxWidthnumberMaximum width
align'left' | 'right' | 'center''left'Text alignment
colorColorNameCell text color
hiddenbooleanfalseHide column
prioritynumber0Responsive priority (higher = hidden first)
wrapWordbooleanfalseWord wrap
truncatestring'…'Truncation character
paddingLeftnumber1Left padding
paddingRightnumber1Right padding

Row

Property / MethodTypeDescription
cellsCell[]Array of cells in this row
getData()anyReturns the original data passed to addRow()

Cell

PropertyTypeDescription
contentstringCell text content
colSpannumberHorizontal span (default: 1)
rowSpannumberVertical span (default: 1)
alignstringOverride alignment for this cell
vAlignstringVertical alignment ('top', 'middle', 'bottom')

InteractiveTable

ts
new InteractiveTable(table: Table, options: InteractiveOptions)
OptionTypeDescription
onSelect(rows: Row[]) => voidSelection callback
onExit() => voidExit callback
MethodDescription
start()Launch the TUI

AsyncInteractiveTable

ts
new AsyncInteractiveTable(source: IDataSource, template: Table)
MethodDescription
start()Launch the async TUI

IDataSource

Interface for async data sources:

MethodRequiredDescription
count()Return total row count
getRows(offset, limit)Fetch a page of rows
sort(column, direction)OptionalSort server-side
filter(query)OptionalFilter server-side

Analysis

Aggregations

MethodDescription
Aggregations.sum(values)Sum of values
Aggregations.avg(values)Average
Aggregations.min(values)Minimum
Aggregations.max(values)Maximum
Aggregations.count(values)Count
Aggregations.stdDev(values)Standard deviation
Aggregations.variance(values)Variance
Aggregations.percentile(values, p)Percentile (0-1)

PivotTable

ts
PivotTable.create(data, { groupBy, targetColumn, algorithm, pivotColumn?, onError? })

CrossTab

ts
CrossTab.create(data, { rowKey, colKey, valueKey, aggregator, missingValue? })

Integrations

ClassStatic Methods
CsvTable.from(csv, opts?), .toCsv(table)
HtmlTable.from(html), .toHtml(table)
JsonTable.toJson(table)
SqlDataSourcenew SqlDataSource(db, tableName)

Utilities

FunctionDescription
colorize(text, color)Wrap text in ANSI color codes
Sparkline.generate(values)Generate sparkline string
Heatmap.color(value, min, max, mode?)Colorize a value on red→green gradient
Heatmap.autoColor(values, min, max)Colorize an array of values