Skip to content

ItemTable

final class Phui\Components\ItemTable

A virtualised table with a header row and one selected row. Columns are sized from their widest header or cell, capped at maxRowWidth, and cells too wide for their column are truncated with an ellipsis. The number of columns comes from headers — extra cells in a row are ignored, missing ones render blank. Takes focus.

A three column table with the second row selected

php
use Phui\Components\ItemTable;
use Phui\Events\EmitEvent;

ItemTable::mount()
    ->props(
        headers: ['Name', 'Size', 'Modified'],
        rows: $this->files,
        selected: $this->cursor,
    )
    ->on('change', fn (EmitEvent $e) => $this->cursor = $e->data)
    ->on('activate', fn (EmitEvent $e) => $this->open($e->data));

Props

PropTypeDefaultDescription
headersarray<int, scalar>[]The header cells, which also fix the column count. Compared deeply.
rowsarray<int, array<array-key, scalar>>[]The body rows. Compared deeply.
maxRowsint50Rows visible before the table scrolls.
maxRowWidthint50Widest a single column may grow.
separatorstring'│'Drawn between columns.
selectedCharstring'→'Marker beside the selected row.
unselectedCharstring' 'Marker beside every other row.

Models

The component holds this and emits on every change. Pass it as a prop to take ownership, and handle its emit — see binding a value both ways.

ModelTypeDefaultEmits
selectedint0change

Emits

EventPayloadEmitted when
changeintThe selected row moves.
activateintThe selected row is activated.

Input

InputAction
kPrevious row
jNext row
Enter SpaceActivate row
Left clickSelect the clicked row

Colours

Phui\Components\Colours\ItemTableColours

ColourPalette defaultUsed for
headertextThe header row at rest.
headerFocusedaccentThe header row while focused.
rowtextUnselected rows, and the selected row while unfocused.
rowSelectedaccentThe selected row while focused.
markermutedThe marker beside unselected rows.
markerSelectedaccentThe marker beside the selected row.
separatorsurfaceThe column separators and the rule under the header.
scrollThumbaccentThe scrollbar thumb.

Released under the MIT License.