btn_edit(), btn_view(), btn_clone(), btn_delete() table()
The usual row buttons, each a btn() with its own default link, icon and admin class.
table()->btn_edit($name = '', $link = '', $extra = [])
table()->btn_view($name = '', $link = '', $extra = [])
table()->btn_clone($name = '', $link = '', $extra = [])
table()->btn_delete($name = '', $link = '', $extra = [])Options
| Option | Meaning |
|---|---|
$name | Button text; default Edit, View, Clone, Delete. The options array may come first. |
$link | Default url('/@object/edit/%d'), view/%d, clone_item/%d, delete/%d. |
no_ajax | Do not add the ajax class (ajax_edit, ajax_view, ajax_clone, ajax_delete btn-danger) that opens the admin modal. |
post | false: delete and clone stay plain links even when the table POSTs its state-changing buttons. |
(btn options) | Every option of btn(). |
Example
Code
$rows = [
1 => ['id' => 1, 'name' => 'Desk lamp'],
2 => ['id' => 2, 'name' => 'Office chair'],
];
return table($rows, ['no_pages' => 1])
->text('name')
->btn_edit(['link' => '#edit-%d', 'no_ajax' => 1])
->btn_view('Preview', '#view-%d', ['no_ajax' => 1])
->btn_clone(['link' => '#clone-%d', 'no_ajax' => 1])
->btn_delete(['link' => '#delete-%d', 'no_ajax' => 1]);Notes
- Each button has
data-test(edit,view,clone,delete) for browser tests. - In the admin with the CSRF guard on (or the table option
post_buttons), delete and clone getdata-yf-post: the admin script sends them as a POST with the token, and a plain GET of those actions answers with a confirm form.
Bootstrap 3 and 5
The delete button is red under both: btn-danger replaces the outline colour of Bootstrap 5.
See also: table/btn, table/btn_active, htmx/admin_confirm, demo:table/filter