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
| Option | Meaning |
|---|---|
$link | URL of the button: %d is the row id (or the field named by id), %<field> that field, URL-encoded. |
icon | Icon class; default CLASS_ICON_BTN (fa fa-tasks). |
class, a_class, class_add | Classes replacing CLASS_BTN_MINI, or added to it. |
id | Field that replaces %d; default id. |
link_params | Comma-separated fields whose %<field> placeholders are replaced. |
rewrite | true, user or admin: the link goes through url(), url_user() or url_admin(). |
title, desc | Title attribute; default the button name. |
btn_no_text | Icon only. |
no_ajax | Adds CLASS_NO_AJAX, so the admin script does not open it in a modal. |
renderer | a (default) or button. |
target, hidden_toggle, hidden_data | Link target; data-hidden-toggle; extra hidden fields of the row. |
display_func | Callback fn ($row, $info, $params, $table); a false answer hides the button in that row. |
Example
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