Table #
PhpTui\Tui\Extension\Core\Widget\TableWidget
Shows tabular data arranged in columns. The column spacing is determined by the “width” constraints.
Example #
Show code
<?php
use PhpTui\Tui\DisplayBuilder;
use PhpTui\Tui\Extension\Core\Widget\Table\TableCell;
use PhpTui\Tui\Extension\Core\Widget\Table\TableRow;
use PhpTui\Tui\Extension\Core\Widget\TableWidget;
use PhpTui\Tui\Layout\Constraint;
require 'vendor/autoload.php';
$display = DisplayBuilder::default()->build();
$display->draw(
TableWidget::default()
->widths(
Constraint::percentage(25),
Constraint::percentage(25),
Constraint::percentage(50),
)
->header(
TableRow::fromStrings(
'Name',
'Quantity',
'Approved?',
)->height(2)->bottomMargin(2)
)
->rows(
TableRow::fromCells(
TableCell::fromString('Cliff'),
TableCell::fromString('1'),
TableCell::fromString('✅'),
),
TableRow::fromStrings(
'Tree',
'15',
'✅',
),
TableRow::fromStrings(
'Slate',
'519',
'✅',
),
)
);
Parameters #
Configure the widget using the builder methods named as follows:
Name | Type | Description |
---|---|---|
style | PhpTui\Tui\Style\Style | Style of the area occupied by the table. |
widths | list<Constraint> | Constraints to use to determine the column widths. |
columnSpacing | int | Spacing to enforce between columns. |
highlightStyle | PhpTui\Tui\Style\Style | Style used when a row is highlighted. |
highlightSymbol | string | Symbol to show when the row is highlighted. |
header | PhpTui\Tui\Extension\Core\Widget\Table\TableRow|null | Optional header. |
rows | list<TableRow> | Table rows. |
highlightSpacing | PhpTui\Tui\Extension\Core\Widget\List\HighlightSpacing | Highlight spacing strategy. |
state | PhpTui\Tui\Extension\Core\Widget\Table\TableState | Hold the state of the table (i.e. selected row, current offset). |