← All libraries

SugarTable

SugarTable

Full-featured interactive data table

port of Evertras/bubble-table tabledatagridinteractive

Column-definition table with sortable columns, frozen rows/cols, per-cell styling, pagination, and selectable rows. StyledCell supports full ANSI formatting.

Install

composer require sugarcraft/sugar-table

Quickstart

use SugarCraft\Table\{Table, Column, Row, RowData, StyledCell, ColumnWidth, WrapMode};

$table = (new Table())
    ->withColumns([
        Column::new('name', 'Name', 20)->withAlignLeft()
            ->withColumnWidth(ColumnWidth::Dynamic, 0),
        Column::new('role', 'Role', 15)->withColumnWidth(ColumnWidth::Percent, 25.0),
        Column::new('age',  'Age',   5)->withWrapMode(WrapMode::None),
    ])
    ->withRows([
        Row::new(RowData::from(['name' => 'Alice', 'role' => 'Admin', 'age' => '30'])),
        Row::new(RowData::from(['name' => 'Bob',   'role' => 'Dev',   'age' => '28'])),
    ])
    ->withPageSize(25);

echo $table->view();

What's in the box

Column definitionsWidth, alignment, frozen, sortable per column.
StyledCellFull ANSI SGR support in every cell — colors, bold, underline.
PaginationPaginate large datasets, navigate between pages.
Frozen rows/colsStick a row at the top or a column on the left.
Row selectionClick or arrow-key row selection with highlight.
Viewport virtualizationRender only visible rows with withViewportHeight() + withScrollY().
Column width modesColumnWidth enum — Fixed, Percent, Dynamic, Content.
Cell text wrappingWrapMode enum — None, WordWrap, Character.
Border stylingwithBorder(Border) — 8 border families from \SugarCraft\Sprinkles\Border.
Multi-line rowswithMultilineMode(bool) — rows expand to max cell height.

Source & demos

Try the quickstart →

API

ClassMethodDescription
TablewithColumns(columns)Set table columns
TablewithRows(rows)Set table rows
TablewithPageSize(size)Set rows per page for pagination
TablewithPage(n)Jump to page n
TablewithViewportHeight(n)Render only n visible rows (viewport virtualization)
TablewithScrollY(n)Set vertical scroll offset (row number)
TablescrollY()Get current scroll offset
Tableview()Render the table to string
TablecomputeColumnWidths(total)Compute actual widths from ColumnWidth enum values
TablewithBorder(border)Set border family (Border::normal/rounded/thick/double/block/ascii/hidden/markdownBorder)
TablewithBorderStyle(ansiStyle)Apply ANSI SGR style to default border
TablewithMultilineMode(bool)Enable multi-line rows (expands to max cell height)
Columnnew(key, title, width)Create a column
ColumnwithAlignLeft(bool)Left-align (default is right)
ColumnwithColumnWidth(mode, value)Set ColumnWidth::Fixed|Percent|Dynamic|Content
ColumnwithWrapMode(mode)Set WrapMode::None|WordWrap|Character
Rownew(rowData)Create a row from RowData
RowDatafrom(array)Create from key-value array
StyledCellnew(value, style)Create styled cell with ANSI style
ColumnWidthenumFixed | Percent | Dynamic | Content
WrapModeenumNone | WordWrap | Character

Demos.

VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.

Frozen + paginated

Frozen + paginated

Wide host-telemetry table with pagination + frozen #.
Basic + sort + filter

Basic + sort + filter

Sort by score, filter `name` contains `a`, paginate.