btn() table()

A button (link) in the actions column of every row; %d and %<field> in the link come from the row.

table()->btn($name, $link, $extra = [])

Options

OptionMeaning
$linkURL of the button: %d is the row id (or the field named by id), %<field> that field, URL-encoded.
iconIcon class; default CLASS_ICON_BTN (fa fa-tasks).
class, a_class, class_addClasses replacing CLASS_BTN_MINI, or added to it.
idField that replaces %d; default id.
link_paramsComma-separated fields whose %<field> placeholders are replaced.
rewritetrue, user or admin: the link goes through url(), url_user() or url_admin().
title, descTitle attribute; default the button name.
btn_no_textIcon only.
no_ajaxAdds CLASS_NO_AJAX, so the admin script does not open it in a modal.
renderera (default) or button.
target, hidden_toggle, hidden_dataLink target; data-hidden-toggle; extra hidden fields of the row.
display_funcCallback fn ($row, $info, $params, $table); a false answer hides the button in that row.

Example

Name Actions
Desk lamp Log
Office chair Log Reorder

Code

$rows = [
    1 => ['id' => 1, 'name' => 'Desk lamp', 'sku' => 'LAMP-01', 'stock' => 12],
    2 => ['id' => 2, 'name' => 'Office chair', 'sku' => 'CHAIR-07', 'stock' => 0],
];
return table($rows, ['no_pages' => 1])
    ->text('name')
    ->btn('Log', '#log-%d', ['icon' => 'fa fa-history'])
    ->btn('Barcode', '#barcode-%sku', ['icon' => 'fa fa-barcode', 'link_params' => 'sku', 'btn_no_text' => 1])
    ->btn('Reorder', '#reorder-%d', ['class_add' => 'btn-warning', 'display_func' => fn ($row) => ! $row['stock']]);

Notes

  • The button name is translated with t().
  • In the admin a button the current admin group may not open is not printed (super-admins see all).
  • With buttons_group / buttons_dropdown_after (render()) the buttons share one group or move into a menu.

Bootstrap 3 and 5

CLASS_BTN_MINI is btn btn-default btn-mini btn-xs under Bootstrap 3 and btn btn-outline-secondary btn-sm under 5; a class_add colour (btn-warning) replaces the outline colour there.

See also: table/btn_func, table/btn_edit, demo:table/bs5_components