Row Actions
Introduction
Row Actions can be used to perform actions on a single row in a table. Row Actions can be configured to require a confirmation dialog before performing the action. Just like Row Links, Row Actions require the ActionColumn
to be included in the Table's column array.
use InertiaUI\Table\Columns;
class Users extends Table
{
public function columns(): array
{
return [
Columns\TextColumn::make('email'),
Columns\ActionColumn::new(),
];
}
}
Defining Row Actions
To define a Row Action, pass the label as the first argument and use the handle
argument to define the action to be performed. The handle
argument should be a callback that accepts the Model instance as the first argument.
use App\Models\User;
use InertiaUI\Table\Action;
class Users extends Table
{
public function actions(): array
{
return [
Action::make('Activate', handle: fn (User $user) => $user->activate()),
];
}
}
Note that the handle
callback is performed using a regular HTTP request, so make sure that the action doesn't take too long to complete. If you need to perform a long-running task, consider using a queued job.
Redirecting After Action
You can redirect the user to a different URL after the action is performed by using the after
argument on the make()
method. The after
argument accepts both a string URL or a callback that returns a URL.
Action::make(
label: 'Activate',
handle: fn (User $user) => $user->activate(),
after: '/activated-users'
);
Confirmation Dialog
By default, Row Actions will not show a confirmation dialog before performing the action. To enable a confirmation dialog, use the confirm
argument on the Action
instance:
Action::make('Delete', handle: fn (User $user) => $user->delete())->confirm();
Here are the default texts for the confirmation dialog:
Text | Default Value |
---|---|
Title | "Confirm action" |
Message | "Are you sure you want to perform this action?" |
Confirm Button | "Yes" |
Cancel Button | "Cancel" |
You can customize the confirmation dialog by passing alternative texts to the confirm()
method:
Action::make('Delete', handle: fn (User $user) => $user->delete())->confirm(
title: 'Delete User',
message: 'Are you sure you want to delete this user?',
confirmButton: 'Delete',
cancelButton: 'Cancel'
);
Alternatively, you may pass the texts as named arguments to the make()
method, but this also requires passing the confirmRequired
argument as true
:
Action::make(
label: 'Delete',
handle: fn (User $user) => $user->delete(),
confirmationRequired: true,
confirmationTitle: 'Delete User',
confirmationMessage: 'Are you sure you want to delete this user?',
confirmationConfirmButton: 'Delete',
confirmationCancelButton: 'Cancel'
);
Action Button styling
You can customize the button styling by passing a class name to the buttonClass
argument: To display a row link as a primary or danger button, you can use the asPrimaryButton()
or asDangerButton()
method.
Action::make('Activate', handle: fn (User $user) => $user->activate())->asPrimaryButton();
Action::make('Suspend', handle: fn (User $user) => $user->delete())->asDangerButton();
Alternatively, you can use the style
argument to specify the button style with the ActionStyle enum.
use InertiaUI\Table\ActionStyle;
Action::make(
label: 'Activate',
handle: fn (User $user) => $user->activate(),
style: ActionStyle::PrimaryButton
);
Authorization
You can use the authorize
argument to define a boolean or callback that determines if the action should be available for the current user. The callback should return a boolean value and accepts the current Request instance as the first argument.
Action::make(
label: 'Delete',
handle: fn (User $user) => $user->delete(),
authorize: fn (Request $request) => $request->user()->can('delete', User::class)
);