Buttons โ
PowerComponents\LivewirePowerGrid\Button configures row actions (actions()) and header actions (header()). For placement, see Row Buttons and Bulk Actions.
Button Methods โ
Methods below are native on Button or registered as macros. Chain them. Params are array values โ there is no automatic substitution of 'id' for the row primary key; pass $row->id (or another field) yourself.
add() โ
Creates a button. $action is the internal name (used by actionRules()).
| Parameter | Description |
|---|---|
| (string) $action | Internal name. Default ''. |
use PowerComponents\LivewirePowerGrid\Button;
Button::add('edit-product'),make() โ
Creates a button and sets the slot in one call.
| Parameter | Description |
|---|---|
| (string) $action | Internal name |
| (?string) $slot | Button content |
Button::make('edit-product', 'Edit'),slot() โ
Sets the button content (HTML string).
| Parameter | Description |
|---|---|
| (?string) $slot | HTML string |
Button::add('edit-product')
->slot('⚡ Edit'),icon() โ
Renders a Blade component as the icon. $icon must resolve as a Blade component โ typically an anonymous component. If it does not resolve, no icon is rendered.
With resources/views/components/icons/trash.blade.php, pass icons.trash:
use PowerComponents\LivewirePowerGrid\Button;
Button::add('delete-product')
->icon('icons.trash')
->class('bg-red-500 text-white'),TIP
Packaged icons use the package namespace, e.g. ->icon('livewire-powergrid::icons.trash').
Pass HTML attributes for the icon as the second argument:
Button::add('delete-product')
->icon('icons.trash', ['id' => 'my-custom-icon-id', 'class' => 'w-5 text-red-600'])
->class('bg-red-500 text-white'),| Parameter | Description |
|---|---|
| (string) $icon | Blade component name to render as the icon |
| (array) $iconAttributes | HTML attributes forwarded to the icon component |
view() โ
Render a Blade view instead of the default <button> / <a> markup. The view receives action (the Button instance) and row.
| Parameter | Description |
|---|---|
| (string) $view | View name |
Button::add('custom')
->view('components.product-action'),class() โ
Sets the class HTML attribute.
| Parameter | Description |
|---|---|
| (string) $classes | CSS class |
Button::add('create-product')
->slot('Create a product')
->class('bg-indigo-500 text-white'),attributes() โ
Merges HTML attributes onto the element. Existing keys on the button win over new ones.
Button::add('create-product')
->slot('Create a product')
->attributes([
'id' => 'my-custom-id',
'class' => 'another-class',
]),<button id="my-custom-id" class="another-class">Create a product</button>id() โ
Sets the id HTML attribute. The value is used as given; it is not suffixed with the row primary key.
| Parameter | Description |
|---|---|
| (?string) $id | HTML id. Default null. |
Button::add('view')
->slot('View')
->id('view-product'),tag() โ
Sets the HTML tag. Default button. route() and link() set this to a.
| Parameter | Description |
|---|---|
| (?string) $tag | Tag name. null keeps the current. |
Button::add('download-recipe')
->slot('Download Recipe')
->tag('a')
->attributes([
'href' => url('/destination-to-file.pdf'),
]),tooltip() โ
Sets the title attribute.
| Parameter | Description |
|---|---|
| (string) $value | Tooltip |
Button::add('edit-product')
->slot('Edit')
->route('product.edit', ['product' => $row->id])
->tooltip('Edit Record'),order() โ
Display order among header buttons. Lower values render first. null (default) keeps declaration order. Row actions ignore this.
| Parameter | Description |
|---|---|
| (int) $order | Sort key |
Button::add('bulk-delete')
->slot('Delete selected')
->order(10),can() โ
Whether the button is rendered. A Closure receives the current $row.
| Parameter | Description |
|---|---|
| (bool, Closure) $can | false hides the button. Default true. |
Button::add('edit-product')
->slot('Edit')
->route('product.edit', ['product' => $row->id])
->can(auth()->check()),
Button::add('delete-product')
->slot('Delete')
->can(fn ($row) => $row->is_deletable),disable() โ
Adds disabled="disabled" when $disable is true.
| Parameter | Description |
|---|---|
| (bool) $disable | Default true. |
Button::add('edit-product')
->slot('Edit')
->disable($row->locked),dispatch() โ
Dispatches a Livewire event (wire:click="$dispatch(...)").
| Parameter | Description |
|---|---|
| (string) $event | Event name |
| (array) $params | Event payload |
Button::add('edit-product')
->slot('Edit')
->class('bg-indigo-500 text-white')
->dispatch('postAdded', ['key' => $row->id]),<button wire:click="$dispatch('postAdded', { key: 1 })">dispatchTo() โ
Dispatches to another component ($dispatchTo).
| Parameter | Description |
|---|---|
| (string) $to | Component name |
| (string) $event | Event name |
| (array) $params | Event payload |
Button::add('view')
->slot('View')
->class('bg-indigo-500 text-white')
->dispatchTo('admin-component', 'postAdded', ['key' => $row->id]),<button wire:click="$dispatchTo('admin-component', 'postAdded', { key: 1 })">dispatchSelf() โ
Dispatches to this component only ($dispatchSelf).
| Parameter | Description |
|---|---|
| (string) $event | Event name |
| (array) $params | Event payload |
Button::add('refresh')
->slot('Refresh')
->dispatchSelf('refreshData', ['force' => true]),call() โ
Calls a method on this table ($call).
| Parameter | Description |
|---|---|
| (string) $method | Method name |
| (array) $params | Method payload |
Button::add('delete-product')
->slot('Delete')
->call('deleteItem', ['id' => $row->id]),<button wire:click="$call('deleteItem', { id: 1 })">parent() โ
Calls a method on the parent Livewire component ($parent).
| Parameter | Description |
|---|---|
| (string) $method | Method name |
| (array) $params | Method payload |
Button::add('notify')
->slot('Notify')
->parent('notifyParent', ['id' => $row->id]),The rendered button emits wire:click="$parent.notifyParent({id: 1})".
openModal() โ
Dispatches openModal with component and arguments. Pairs with wire-elements/modal, or any listener you register for openModal.
| Parameter | Description |
|---|---|
| (string) $component | Component to open |
| (array) $params | Component arguments |
Button::add('view')
->slot('View')
->class('bg-indigo-500 text-white')
->openModal('view-product', ['product' => $row->id]),route() โ
Renders an <a> whose href is a named Laravel route.
| Parameter | Description |
|---|---|
| (string) $route | Route name |
| (array) $params | Route parameters |
| (string) $target | href target. Default _self. |
Button::add('view')
->slot('View')
->class('bg-indigo-500 text-white')
->route('product.edit', ['product' => $row->id], '_blank'),link() โ
Renders an <a> with a raw URL (no named route).
| Parameter | Description |
|---|---|
| (string) $href | URL |
| (string) $target | href target. Default _self. |
Button::add('docs')
->slot('Docs')
->link('https://example.com/docs', '_blank'),toggleDetail() โ
Toggles the Detail Row for the given row id (wire:click="toggleDetail('โฆ')").
| Parameter | Description |
|---|---|
| (int, string) $rowId | Row id |
Button::add('toggle-detail')
->slot('Toggle Detail')
->toggleDetail($row->id),confirm() โ
Adds wire:confirm before the click action. Omit $message to use the translated default (livewire-powergrid::datatable.buttons_macros.confirm.message).
| Parameter | Description |
|---|---|
| (?string) $message | Message |
Button::add('edit')
->confirm('Are you sure you want to edit?'),<button wire:confirm="Are you sure you want to edit?">confirmPrompt() โ
Adds wire:confirm.prompt. The user must type $confirmValue. Omit $message to use the translated default.
| Parameter | Description |
|---|---|
| (?string) $message | Message |
| (string) $confirmValue | Required input. Default Confirm. |
Button::add('edit')
->confirmPrompt('Are you sure you want to edit?', 'EDIT'),<button wire:confirm.prompt="Are you sure you want to edit? | EDIT">Conditional Formatting โ
See Conditional Rules.
Extending the Button Class โ
Button is Macroable. attributes stores HTML attributes you can set from a custom method.
use PowerComponents\LivewirePowerGrid\Button;
Button::macro('navigate', function () {
$this->attributes([
'wire:navigate' => true,
]);
return $this;
});Button::add('new-modal')
->slot('New window')
->class('bg-gray-300')
->navigate(),