← All 40 libraries

SugarTable

SugarTable

Full-featured interactive data table

inspired by Evertras/bubble-table tabledatagridinteractive

SugarTable code coverage

Column-definition table with sortable columns, frozen columns, per-cell styling, pagination, and a programmatic row cursor. StyledCell supports full ANSI formatting.

Install

composer require sugarcraft/sugar-table

Quickstart

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

$table = Table::fromColumns([
        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 columnsPin the leftmost columns with withFrozenCols([0..k]) so they stay put during horizontal scroll.
Row selectionProgrammatic cursor - SelectNext/SelectPrevious/withSelectedIndex; handleKey(KEY_*) scrolls. No mouse handling: wire input events yourself.
Viewport virtualizationRender only visible rows with withViewportHeight() + withScrollY().
Column width modesColumnWidth enum — Fixed, Percent, Dynamic, Content, Flex.
Borderless + width-exactwithBorderless() + withWidth() — compose inside another box at an exact width, with continuous reverse-video selection.
Cell text wrappingWrapMode enum — None, WordWrap, Character.
Border stylingwithBorder(Border) — 8 border families from \SugarCraft\Style\Border.
Multi-line rowswithMultilineMode(bool) — rows expand to max cell height.

Accessors

Property reads are bare: public readonly state ($column->style, $row->data, $cell->value) or bare methods (Table::Rows(), scrollY()). No getFoo()-form accessor ships in this lib — under the get*-era ruling (2026-10-24) there was nothing here to deprecate; RowData::get()/::has() and Table::isExpanded() stay ruled as keyed lookups and predicates, pinned by tests/BareAccessorEraTest.php.

Source & demos

Try the quickstart →

API

ClassMethodDescription
Tablestatic fromColumns(columns) / withColumns(columns)Create a table from its columns / replace them
TablewithRows(rows)Set table rows
TablewithPageSize(size)Set rows per page for pagination
TablewithPage(n)Jump to page n (0-based; PageFooter shows n+1)
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
TableSortBy(key, ascending)Sort rows by a column (plain-text comparison)
TableFilter(key, text) / ClearFilter(key) / ClearAllFilters()Per-column substring filter (filterable-marked columns only once any is marked)
Tablesearch(text) / ClearSearch()OR search across the scanned columns
TablehandleKey(KEY_*)Keyboard scrolling - KEY_ARROW_UP/DOWN, PAGE_UP/DOWN, HOME, END; clamps to maxScrollY()
TableSelectNext() / SelectPrevious()Move the row cursor (follows the viewport)
TablemaxScrollY()Highest valid scrollY for the current page + viewport (public, page-aware)
TablewithFrozenCols(indices)Pin a contiguous prefix [0..k]; anything else throws
TablewithHiddenCols(indices) / withScrollX(cols)Hide columns (must stay disjoint from the frozen prefix) / pan the scrollable region
TablewithExpandedRows(i) / toggleExpanded(i) / isExpanded(i)Row detail expansion tracked by Row object identity (withRows() prunes stale identities)
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|Flex
ColumnwithWrapMode(mode)Set WrapMode::None|WordWrap|Character
Rownew(rowData)Create a row from RowData
RowDatafrom(array)Create from key-value array
RowDataget(key) / has(key) / all() / with(key, value)Keyed map lookup, presence test, full map, immutable set (ruling-3b keepers — not getFoo()-form accessors)
StyledCellnew(value, style)Create styled cell with ANSI style
ColumnWidthenumFixed | Percent | Dynamic | Content | Flex
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.