Full-featured interactive data table
Column-definition table with sortable columns, frozen rows/cols, per-cell styling, pagination, and selectable rows. StyledCell supports full ANSI formatting.
composer require sugarcraft/sugar-table
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();
| Class | Method | Description |
|---|---|---|
| Table | withColumns(columns) | Set table columns |
| Table | withRows(rows) | Set table rows |
| Table | withPageSize(size) | Set rows per page for pagination |
| Table | withPage(n) | Jump to page n |
| Table | withViewportHeight(n) | Render only n visible rows (viewport virtualization) |
| Table | withScrollY(n) | Set vertical scroll offset (row number) |
| Table | scrollY() | Get current scroll offset |
| Table | view() | Render the table to string |
| Table | computeColumnWidths(total) | Compute actual widths from ColumnWidth enum values |
| Table | withBorder(border) | Set border family (Border::normal/rounded/thick/double/block/ascii/hidden/markdownBorder) |
| Table | withBorderStyle(ansiStyle) | Apply ANSI SGR style to default border |
| Table | withMultilineMode(bool) | Enable multi-line rows (expands to max cell height) |
| Column | new(key, title, width) | Create a column |
| Column | withAlignLeft(bool) | Left-align (default is right) |
| Column | withColumnWidth(mode, value) | Set ColumnWidth::Fixed|Percent|Dynamic|Content |
| Column | withWrapMode(mode) | Set WrapMode::None|WordWrap|Character |
| Row | new(rowData) | Create a row from RowData |
| RowData | from(array) | Create from key-value array |
| StyledCell | new(value, style) | Create styled cell with ANSI style |
| ColumnWidth | enum | Fixed | Percent | Dynamic | Content |
| WrapMode | enum | None | WordWrap | Character |
VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.