btn_func() table()

A cell of the actions column rendered by your callback, for buttons that need the whole row.

table()->btn_func($name, $func, $extra = [])

Options

OptionMeaning
$funcCallback fn ($row, $info, $params, $table) returning the HTML of the button.
descName used in $info; default from $name.
display_funcCallback; a false answer hides it in that row.

Example

Name Actions
Desk lamp Open
Office chair no page

Code

$rows = [
    1 => ['id' => 1, 'name' => 'Desk lamp', 'url' => 'https://example.com/lamp'],
    2 => ['id' => 2, 'name' => 'Office chair', 'url' => ''],
];
return table($rows, ['no_pages' => 1])
    ->text('name')
    ->btn_func('open', fn ($row) => $row['url']
        ? '<a class="btn btn-default btn-outline-secondary btn-xs btn-sm" href="' . _prepare_html($row['url']) . '" rel="noopener" target="_blank">Open</a>'
        : '<span class="text-muted">no page</span>');

Notes

  • The callback returns HTML: escape row values with _prepare_html().

See also: table/btn, table/func