Common column options table()

Options every column method takes in its $extra array: header, width, tips, cell attributes, transforms and visibility.

Options

OptionMeaning
descHeader text (also the second argument of text(), date(), stars()).
th_descHeader text that wins over desc.
th, th_idAttributes of the header cell (string or [class, id, width]); its id.
widthWidth of the header and the cells (80, 20%).
nowrapThe cells do not wrap.
header_tip, tipA help icon with a popover in the header; in each cell (a string, or value => text map).
tdCell attributes: a string, or a callback fn ($row, $name, $row_id).
transformA callable or |-separated function names applied to the value (trim|strtoupper).
wordwrapWrap long values at this many characters.
hl_filterHighlight the filter value in the cell.
display_funcCallback fn ($row, $info, $params, $table); a false answer leaves the cell empty for that row.
badge / label / classWrap 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).
  • transform may name PHP functions: it comes from site code, never from request data.
  • A value => colour map of badge / label that lacks a value shows that value plain (fixed 2026-11-15: it was a TypeError). A class map that lacks it prints class="Array" with a PHP warning unless yf_table2::$MAP_MISS_PLAIN is on ($PROJECT_CONF['table2']['MAP_MISS_PLAIN'], Settings / Widget fixes; the 4.0 default), which adds no class.

See also: table/text, table/func