/

Custom Row Buttons

Add a per-row action button - confirmations, live conditions, and an input-collecting prompt modal, all via ->button().

Adding a button

->button($label, $functionName, $options = []) adds a custom action button next to the built-in Edit/Remove buttons on every row. $functionName is a server-side function (usually in functions.php) that receives the row's primary key and data:

$xcrud->button('Process', 'orderdetails_process_line', [
    'icon'    => 'fa fa-cogs',
    'confirm' => 'Process this order line?',
    'before'  => 'Process',
    'loading' => 'Processing…',
    'after'   => 'Processed ✓',
]);

function orderdetails_process_line(mixed $id, array $row, Xcrud $xcrud): string|bool|null
{
    // Do the work here. Return false or a non-empty string to fail/block
    // (the string is shown as the error message). Anything else (true,
    // null, no return) means it succeeded.
    return true;
}

Multiple ->button() calls accumulate - one button per call, same as ->disable_logic()/->hide_logic().

Options

OptionWhat it does
iconAn icon class string, e.g. 'fa fa-check'.
confirmA confirmation message (window.confirm) shown before the action fires. Omit for no confirmation. Ignored whenever prompt is set - the prompt modal's own OK button already is the confirmation.
condition / condition_modeA "field OP value" expression (e.g. 'amount<1000') evaluated against the row's own data, live-reevaluated client-side the instant a referenced field is inline-edited. condition_mode is 'hide' (default, removes the button) or 'disable' (keeps it visible but grayed out).
disable_conditionA second, independent condition, always in disable mode regardless of condition_mode - for "hide under condition A, but also gray out under condition B" in one call.
pathLoads $functionName from a file other than functions.php.
beforeThe button's idle-state text. Defaults to $label.
loadingShown the whole time the click is in flight (same spinner treatment Save/Delete use). Defaults to 'Processing…'.
afterShown briefly once the click succeeds, before reverting to before. Omit to skip and revert immediately.
formAlso show this button in the Edit form's own footer, alongside Save/Close. Off by default.
gridShow this button in the grid's Actions cell/hover/ellipsis menu. On by default.
promptAn array of field definitions - clicking the button opens a small modal first, collecting one value per field before the server call. Reuses the same field controls the real Edit form uses, including a searchable relation dropdown.

Prompt modals

Set prompt to collect input before the handler runs. Each entry needs field, label, and type (text/int/decimal/date/datetime/select/relation). A relation entry takes the same target_table/target_id/target_name/where/order_by/multi/search options ->relation() itself takes:

$xcrud->button('Reassign', 'payments_reassign', [
    'prompt' => [[
        'field' => 'customerNumber', 'label' => 'New customer',
        'type' => 'relation', 'target_table' => 'customers',
        'target_id' => 'customerNumber',
        'target_name' => ['customerName'], 'search' => true,
    ]],
]);

function payments_reassign(mixed $id, array $row, Xcrud $xcrud, array $promptValues): string|bool|null
{
    // $promptValues['customerNumber'] is whatever the visitor picked.
    return true;
}

A handler function that also uses prompt receives a 4th parameter, $promptValues - a plain 3-parameter function like the first example above simply never sees it. $promptValues is always passed (an empty array when prompt was never set).

Actions column placement and style

button_position($position) sets which side of the grid the Actions column sits on - 'left' or 'right' (default).

button_style($style, $showText = null) controls how the per-row Edit/Remove/custom actions are displayed:

StyleBehavior
'buttons' (default)Always visible, exactly as before.
'hover'Invisible until the row is hovered - fades in as a floating popup below the row. Not reachable on touch devices with no hover state.
'reveal'The same hover-triggered fade as 'hover', but the buttons live in normal document flow instead of a floating popup, so the row never overflows onto adjacent rows.
'ellipsis'A single "⋯" button per row opens a small dropdown with the actions as menu items.

This is purely a display choice - ->unset_edit()/->unset_remove() are what actually remove an action; button_style() only changes how the ones that remain are shown. $showText defaults to showing each button's text label next to its icon; pass false to show the icon alone with the label as a hover tooltip instead.

Delete confirmation and the Add button label

$xcrud->remove_confirm('Really delete this record?');
$xcrud->add_button_name('New Payment'); // renders as "+ New Payment"

remove_confirm($message = true) controls the confirmation dialog shown before a delete: true (default) confirms with the standard message, false deletes immediately with no confirmation, and a string confirms showing that exact message instead.