Skip to content

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()).

ParameterDescription
(string) $actionInternal name. Default ''.
phpapp/Livewire/ProductTable.php
use PowerComponents\LivewirePowerGrid\Button;

Button::add('edit-product'),

make() โ€‹

Creates a button and sets the slot in one call.

ParameterDescription
(string) $actionInternal name
(?string) $slotButton content
phpapp/Livewire/ProductTable.php
Button::make('edit-product', 'Edit'),

slot() โ€‹

Sets the button content (HTML string).

ParameterDescription
(?string) $slotHTML string
phpapp/Livewire/ProductTable.php
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:

phpapp/Livewire/ProductTable.php
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:

phpapp/Livewire/ProductTable.php
Button::add('delete-product')
    ->icon('icons.trash', ['id' => 'my-custom-icon-id', 'class' => 'w-5 text-red-600'])
    ->class('bg-red-500 text-white'),
ParameterDescription
(string) $iconBlade component name to render as the icon
(array) $iconAttributesHTML 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.

ParameterDescription
(string) $viewView name
phpapp/Livewire/ProductTable.php
Button::add('custom')
    ->view('components.product-action'),

class() โ€‹

Sets the class HTML attribute.

ParameterDescription
(string) $classesCSS class
phpapp/Livewire/ProductTable.php
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.

phpapp/Livewire/ProductTable.php
Button::add('create-product')
    ->slot('Create a product')
    ->attributes([
        'id' => 'my-custom-id',
        'class' => 'another-class',
    ]),
html
<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.

ParameterDescription
(?string) $idHTML id. Default null.
phpapp/Livewire/ProductTable.php
Button::add('view')
    ->slot('View')
    ->id('view-product'),

tag() โ€‹

Sets the HTML tag. Default button. route() and link() set this to a.

ParameterDescription
(?string) $tagTag name. null keeps the current.
phpapp/Livewire/ProductTable.php
Button::add('download-recipe')
    ->slot('Download Recipe')
    ->tag('a')
    ->attributes([
        'href' => url('/destination-to-file.pdf'),
    ]),

tooltip() โ€‹

Sets the title attribute.

ParameterDescription
(string) $valueTooltip
phpapp/Livewire/ProductTable.php
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.

ParameterDescription
(int) $orderSort key
phpapp/Livewire/ProductTable.php
Button::add('bulk-delete')
    ->slot('Delete selected')
    ->order(10),

can() โ€‹

Whether the button is rendered. A Closure receives the current $row.

ParameterDescription
(bool, Closure) $canfalse hides the button. Default true.
phpapp/Livewire/ProductTable.php
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.

ParameterDescription
(bool) $disableDefault true.
phpapp/Livewire/ProductTable.php
Button::add('edit-product')
    ->slot('Edit')
    ->disable($row->locked),

dispatch() โ€‹

Dispatches a Livewire event (wire:click="$dispatch(...)").

ParameterDescription
(string) $eventEvent name
(array) $paramsEvent payload
phpapp/Livewire/ProductTable.php
Button::add('edit-product')
    ->slot('Edit')
    ->class('bg-indigo-500 text-white')
    ->dispatch('postAdded', ['key' => $row->id]),
html
<button wire:click="$dispatch('postAdded', { key: 1 })">

dispatchTo() โ€‹

Dispatches to another component ($dispatchTo).

ParameterDescription
(string) $toComponent name
(string) $eventEvent name
(array) $paramsEvent payload
phpapp/Livewire/ProductTable.php
Button::add('view')
    ->slot('View')
    ->class('bg-indigo-500 text-white')
    ->dispatchTo('admin-component', 'postAdded', ['key' => $row->id]),
html
<button wire:click="$dispatchTo('admin-component', 'postAdded', { key: 1 })">

dispatchSelf() โ€‹

Dispatches to this component only ($dispatchSelf).

ParameterDescription
(string) $eventEvent name
(array) $paramsEvent payload
phpapp/Livewire/ProductTable.php
Button::add('refresh')
    ->slot('Refresh')
    ->dispatchSelf('refreshData', ['force' => true]),

call() โ€‹

Calls a method on this table ($call).

ParameterDescription
(string) $methodMethod name
(array) $paramsMethod payload
phpapp/Livewire/ProductTable.php
Button::add('delete-product')
    ->slot('Delete')
    ->call('deleteItem', ['id' => $row->id]),
html
<button wire:click="$call('deleteItem', { id: 1 })">

parent() โ€‹

Calls a method on the parent Livewire component ($parent).

ParameterDescription
(string) $methodMethod name
(array) $paramsMethod payload
phpapp/Livewire/ProductTable.php
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.

ParameterDescription
(string) $componentComponent to open
(array) $paramsComponent arguments
phpapp/Livewire/ProductTable.php
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.

ParameterDescription
(string) $routeRoute name
(array) $paramsRoute parameters
(string) $targethref target. Default _self.
phpapp/Livewire/ProductTable.php
Button::add('view')
    ->slot('View')
    ->class('bg-indigo-500 text-white')
    ->route('product.edit', ['product' => $row->id], '_blank'),

Renders an <a> with a raw URL (no named route).

ParameterDescription
(string) $hrefURL
(string) $targethref target. Default _self.
phpapp/Livewire/ProductTable.php
Button::add('docs')
    ->slot('Docs')
    ->link('https://example.com/docs', '_blank'),

toggleDetail() โ€‹

Toggles the Detail Row for the given row id (wire:click="toggleDetail('โ€ฆ')").

ParameterDescription
(int, string) $rowIdRow id
phpapp/Livewire/ProductTable.php
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).

ParameterDescription
(?string) $messageMessage
phpapp/Livewire/ProductTable.php
Button::add('edit')
    ->confirm('Are you sure you want to edit?'),
html
<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.

ParameterDescription
(?string) $messageMessage
(string) $confirmValueRequired input. Default Confirm.
phpapp/Livewire/ProductTable.php
Button::add('edit')
    ->confirmPrompt('Are you sure you want to edit?', 'EDIT'),
html
<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.

phpapp/Providers/AppServiceProvider.php
use PowerComponents\LivewirePowerGrid\Button;

Button::macro('navigate', function () {
    $this->attributes([
        'wire:navigate' => true,
    ]);

    return $this;
});
phpapp/Livewire/ProductTable.php
Button::add('new-modal')
    ->slot('New window')
    ->class('bg-gray-300')
    ->navigate(),

Created By Luan Freitas and @DanSysAnalyst