Bulk Actions
Bulk actions let users select multiple rows in an Inertia Table and run a single action against all of them (deactivate, delete, export, send a message) with one click. They share the same definition as row actions, so there's no separate code path: define an action once, mark it as bulk-capable, and it shows up in the bulk-action menu when rows are selected.
Defining Bulk Actions
Bulk Actions are defined exactly like Row Actions. Use the asBulkAction and onlyAsBulkAction methods to control whether the action is also available as a row action or only as a bulk action.
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())->asBulkAction(),
];
}
}Styling, authorization, confirmation dialogs, and redirecting after the action are all handled the same way as Row Actions.
Before and After Callbacks
You may use the before and after arguments to define callbacks that run before and after the action. Both receive an array of model IDs as the first argument.
Action::make(
label: 'Activate',
before: fn (array $ids) => Log::info('Activating users...', ['ids' => $ids]),
handle: fn (User $user) => $user->activate(),
after: fn () => session()->flash('success', 'Users activated successfully')
)->asBulkAction();Bulk Selection Type v4
By default, the "Select All" checkbox selects all items across every page. Set the bulkSelectionType property on your Table class to BulkSelectionType::Page to limit selection to the current page only.
use InertiaUI\Table\BulkSelectionType;
class Users extends Table
{
protected ?BulkSelectionType $bulkSelectionType = BulkSelectionType::Page;
}You may also set it fluently:
Table::build(resource: User::class)->bulkSelectionType(BulkSelectionType::Page);To apply the same behavior to all tables, call the static defaultBulkSelectionType() method, typically in your AppServiceProvider:
use InertiaUI\Table\BulkSelectionType;
use InertiaUI\Table\Table;
Table::defaultBulkSelectionType(BulkSelectionType::Page);The default value is BulkSelectionType::All.
Making Rows Unselectable
You may control whether a row is selectable by implementing the isSelectable method on your Table class:
use Illuminate\Database\Eloquent\Model;
class Users extends Table
{
public function isSelectable(Model $model): bool
{
return ! $model->trashed();
}
}This only disables the checkbox for the row. The Row Action is still executable unless you disable it separately. See the Row Actions documentation for details.
Chunk Size
The default chunk size for bulk actions is 1000. Change it by passing the chunkSize argument to make():
Action::make(
label: 'Activate',
handle: fn (User $user) => $user->activate(),
chunkSize: 500
)->asBulkAction();Chunk Method
By default, the database is queried using the chunkById method. To use chunk instead, pass eachById: false to make():
Action::make(
label: 'Activate',
handle: fn (User $user) => $user->activate(),
eachById: false
)->asBulkAction();See the Laravel documentation for the differences between chunkById and chunk. chunkById is generally recommended when updating or deleting records.
Authorization
Use the authorize argument to pass a boolean or callback that determines whether the action is available to the current user. The callback returns a boolean and receives the current Request as its first argument. Unauthorized Bulk Actions are disabled in the Bulk Actions dropdown.
Action::make(
label: 'Delete',
handle: fn (User $user) => $user->delete(),
authorize: fn (Request $request) => $request->user()->can('delete', User::class)
)->asBulkAction();In earlier versions of the package, the disabled and hidden methods did not exist, and authorize was the only way to disable or hide an action. The model instance is not passed to the authorize callback, so authorization via authorize is global, not per-row. See the Row Actions documentation for per-row disabling.
Data Attributes and Metadata
See the Row Links documentation for details on adding Data Attributes and Metadata to Bulk Actions.