Advanced cell configuration with content, styling, spanning, alignment, and hyperlink support for creating rich, customized table cells.
Cells accept various content types for flexibility in data display.
type CellValue = boolean | number | bigint | string | null | undefined;
type Cell = CellValue | CellOptions;Usage Examples:
const Table = require('cli-table3');
const table = new Table();
// Various content types
table.push([
'Text content', // string
42, // number
true, // boolean
BigInt(123456789), // bigint
null, // null (renders as empty)
undefined // undefined (renders as empty)
]);Comprehensive cell options for styling, spanning, and behavior control.
interface CellOptions {
/** The cell content to display */
content: CellValue;
/** Number of columns this cell should span */
colSpan?: number;
/** Number of rows this cell should span */
rowSpan?: number;
/** Horizontal alignment override for this cell */
hAlign?: HorizontalAlignment;
/** Vertical alignment override for this cell */
vAlign?: VerticalAlignment;
/** Style overrides specific to this cell */
style?: Partial<{
'padding-left': number;
'padding-right': number;
head: string[];
border: string[];
}>;
/** Border character overrides for this cell */
chars?: Partial<Record<CharName, string>>;
/** Truncation character override for this cell */
truncate?: string;
/** Word wrap override for this cell */
wordWrap?: boolean;
/** Word boundary wrap override for this cell */
wrapOnWordBoundary?: boolean;
/** URL for terminal hyperlinks */
href?: string;
}Create cells that span multiple columns or rows.
colSpan?: number;
rowSpan?: number;Usage Examples:
// Column spanning
const table = new Table({
head: ['Product', 'Q1', 'Q2', 'Q3', 'Q4']
});
table.push([
'Revenue',
{ content: 'Sales Data', colSpan: 4, hAlign: 'center' }
]);
table.push([
'Laptops',
'$25K', '$30K', '$35K', '$40K'
]);
// Row spanning (requires careful coordination)
const spanTable = new Table();
spanTable.push([
{ content: 'Multi-row\nContent', rowSpan: 2 },
'Row 1 Col 2'
]);
spanTable.push([
'', // Empty cell for row span continuation
'Row 2 Col 2'
]);Override table-level alignment for individual cells.
hAlign?: HorizontalAlignment;
vAlign?: VerticalAlignment;
type HorizontalAlignment = 'left' | 'center' | 'right';
type VerticalAlignment = 'top' | 'center' | 'bottom';Usage Examples:
const table = new Table();
table.push([
{ content: 'Left aligned', hAlign: 'left' },
{ content: 'Centered', hAlign: 'center' },
{ content: 'Right aligned', hAlign: 'right' }
]);
// Vertical alignment (for multi-line content)
table.push([
{ content: 'Top\nAligned\nContent', vAlign: 'top' },
{ content: 'Center\nAligned\nContent', vAlign: 'center' },
{ content: 'Bottom\nAligned\nContent', vAlign: 'bottom' }
]);Individual cell styling overrides.
style?: Partial<{
'padding-left': number;
'padding-right': number;
head: string[];
border: string[];
}>;Usage Examples:
// Individual cell padding
table.push([
{
content: 'Custom padding',
style: {
'padding-left': 3,
'padding-right': 3
}
},
'Normal padding'
]);
// Cell-specific colors (requires @colors/colors)
const colors = require('@colors/colors/safe');
table.push([
{
content: 'Highlighted',
style: {
head: ['red', 'bold'],
border: ['cyan']
}
}
]);Override border characters for individual cells.
chars?: Partial<Record<CharName, string>>;
type CharName =
| 'top' | 'top-mid' | 'top-left' | 'top-right'
| 'bottom' | 'bottom-mid' | 'bottom-left' | 'bottom-right'
| 'left' | 'left-mid' | 'mid' | 'mid-mid'
| 'right' | 'right-mid' | 'middle';Usage Examples:
table.push([
{
content: 'Custom borders',
chars: {
'top': '═',
'bottom': '═',
'left': '║',
'right': '║'
}
},
'Standard borders'
]);Control text wrapping and truncation at the cell level.
truncate?: string;
wordWrap?: boolean;
wrapOnWordBoundary?: boolean;Usage Examples:
const table = new Table({ colWidths: [15, 15] });
table.push([
{
content: 'This is very long text that will be truncated',
truncate: '...'
},
{
content: 'This is very long text that will wrap nicely',
wordWrap: true,
wrapOnWordBoundary: true
}
]);Add clickable hyperlinks to terminal-supported environments.
href?: string;Usage Examples:
table.push([
'Documentation',
{
content: 'Click here',
href: 'https://github.com/cli-table/cli-table3'
}
]);
// Content with different display text
table.push([
'GitHub',
{
content: 'cli-table3 repository',
href: 'https://github.com/cli-table/cli-table3'
}
]);const Table = require('cli-table3');
const colors = require('@colors/colors/safe');
const table = new Table({
head: ['Feature', 'Description', 'Status'],
colWidths: [15, 30, 10]
});
table.push([
// Simple text
'Basic Tables',
// Multi-line with word wrap
{
content: 'Create simple horizontal tables with rows and columns',
wordWrap: true
},
// Styled cell with color
{
content: 'Complete',
hAlign: 'center',
style: { head: ['green'] }
}
]);
table.push([
// Spanning cell
{
content: 'Advanced Features',
colSpan: 2,
hAlign: 'center',
style: { head: ['bold', 'cyan'] }
},
// Status with custom truncation
{
content: 'In Progress',
truncate: '…'
}
]);const salesTable = new Table({
head: ['Product', 'Q1', 'Q2', 'Q3', 'Q4', 'Total']
});
salesTable.push([
'Laptops',
{ content: '$25,000', hAlign: 'right' },
{ content: '$30,000', hAlign: 'right' },
{ content: '$35,000', hAlign: 'right' },
{ content: '$40,000', hAlign: 'right' },
{
content: '$130,000',
hAlign: 'right',
style: { head: ['bold'] }
}
]);
// Add totals row with spanning
salesTable.push([
{
content: 'Grand Total',
colSpan: 5,
hAlign: 'right',
style: { head: ['bold'] }
},
{
content: '$450,000',
hAlign: 'right',
style: { head: ['bold', 'green'] }
}
]);const profileTable = new Table();
profileTable.push(
{ 'Name': { content: 'Alice Johnson', style: { head: ['cyan'] } } },
{ 'Title': 'Senior Developer' },
{ 'Skills': {
content: 'JavaScript, TypeScript, React, Node.js',
wordWrap: true
}
},
{ 'Portfolio': {
content: 'View Projects',
href: 'https://alice-dev.com/portfolio'
}
}
);