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

OptionMeaning
$nameButton text; default Edit, View, Clone, Delete. The options array may come first.
$linkDefault url('/@object/edit/%d'), view/%d, clone_item/%d, delete/%d.
no_ajaxDo not add the ajax class (ajax_edit, ajax_view, ajax_clone, ajax_delete btn-danger) that opens the admin modal.
postfalse: delete and clone stay plain links even when the table POSTs its state-changing buttons.
(btn options)Every option of btn().

Example

Name Actions
Desk lamp Edit Preview Clone Delete
Office chair Edit Preview Clone Delete

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 get data-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