Common column options table()
Options every column method takes in its $extra array: header, width, tips, cell attributes, transforms and visibility.
Options
| Option | Meaning |
|---|---|
desc | Header text (also the second argument of text(), date(), stars()). |
th_desc | Header text that wins over desc. |
th, th_id | Attributes of the header cell (string or [class, id, width]); its id. |
width | Width of the header and the cells (80, 20%). |
nowrap | The cells do not wrap. |
header_tip, tip | A help icon with a popover in the header; in each cell (a string, or value => text map). |
td | Cell attributes: a string, or a callback fn ($row, $name, $row_id). |
transform | A callable or |-separated function names applied to the value (trim|strtoupper). |
wordwrap | Wrap long values at this many characters. |
hl_filter | Highlight the filter value in the cell. |
display_func | Callback fn ($row, $info, $params, $table); a false answer leaves the cell empty for that row. |
badge / label / class | Wrap the value in a badge, label or span of that class (a string or a value => colour map). |
Example
| SKU | Name | Stock | State |
|---|---|---|---|
| LAMP-01 | Desk lamp | 12 | in stock |
| CHAIR-07 | Office chair | 0 | sold out |
Code
$rows = [
1 => ['id' => 1, 'sku' => ' lamp-01 ', 'name' => 'Desk lamp', 'stock' => 12, 'state' => 'in stock'],
2 => ['id' => 2, 'sku' => ' chair-07', 'name' => 'Office chair', 'stock' => 0, 'state' => 'sold out'],
];
return table($rows, ['no_pages' => 1])
->text('sku', ['th_desc' => 'SKU', 'width' => '20%', 'transform' => 'trim|strtoupper'])
->text('name', ['header_tip' => 'Name shown in the shop', 'nowrap' => 1])
->text('stock', ['td' => fn ($row) => $row['stock'] ? '' : 'class="text-danger"'])
->text('state', ['label' => ['in stock' => 'success', 'sold out' => 'danger']]);Notes
- A column whose field is missing from the rows is not shown (a func() column is always shown).
transformmay name PHP functions: it comes from site code, never from request data.- A value => colour map of
badge/labelthat lacks a value shows that value plain (fixed 2026-11-15: it was a TypeError). Aclassmap that lacks it printsclass="Array"with a PHP warning unlessyf_table2::$MAP_MISS_PLAINis on ($PROJECT_CONF['table2']['MAP_MISS_PLAIN'], Settings / Widget fixes; the 4.0 default), which adds no class.
See also: table/text, table/func