Skip to content

Row Buttons โ€‹

Add buttons to each row from actions(). PowerGrid renders them as Blade HTML on the server.

Button appearance and behavior (slot(), class(), dispatch(), route(), can(), confirm(), โ€ฆ) live on the Button class. This page covers how those buttons get onto rows.

Actions Method โ€‹

Define row actions in actions(). You must also add an Action Column.

$row is the current record (Model or array). Use it to pass row-specific values into each Button.

phpapp/Livewire/ProductTable.php
use PowerComponents\LivewirePowerGrid\PowerGridComponent;

class ProductTable extends PowerGridComponent
{
    public function actions($row): array
    {
        return [
            // ...
        ];
    }
}

Defining Row Buttons โ€‹

Return Button instances from actions(). Chain the methods you need from the Button class.

phpapp/Livewire/ProductTable.php
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\Button;

class ProductTable extends PowerGridComponent
{
    public function actions($row): array
    {
        return [
            Button::add('edit-stock') 
                ->slot('Edit <strong>' . e($row->name) . '</strong>')
                ->class('bg-indigo-500 text-white')
                ->dispatch('clickToEdit', ['productId' => $row->id]),
        ];
    }
}

Hide a button for some rows with can() (bool or closure). For style, caption, or disable rules, see Conditional Rules.

phpapp/Livewire/ProductTable.php
Button::add('order')
    ->slot('Order')
    ->class('bg-indigo-500 text-white')
    ->can(fn ($row) => $row->in_stock)
    ->dispatch('orderProduct', ['id' => $row->id]),

Custom Button View โ€‹

To replace one button with a Blade view, chain view(). The view receives $action (the Button) and $row.

phpapp/Livewire/ProductTable.php
Button::add('edit')
    ->view('components.tables.edit-button'),

Actions From Blade View โ€‹

To render a custom view for the whole Action Column cell, add actionsFromView() and return a View. $row is the current record.

You can use this together with actions(), or on its own.

phpapp/Livewire/ProductTable.php
use Illuminate\View\View;

public function actionsFromView($row): View
{
    return view('actions-view', ['row' => $row]);
}
phpresources/views/actions-view.blade.php
<div>
    @if ($row->in_stock)
        <button>Order now</button>
    @else
        - out of stock -
    @endif
</div>

Bulk Actions Buttons โ€‹

See Bulk Actions for header buttons that run on selected rows.

Created By Luan Freitas and @DanSysAnalyst