Workflow
Radio Button
XLSX All
Csv All
Id
Name
Email
Action
1
Luan
luanfreitasdev@fakemail.com
2
Daniel
dansysanalyst@fakemail.com
3
Claudio
claudio@fakemail.com
4
Vitor
vitao@fakemail.com
5
Tio Jobs
tiojobs@fakemail.com
Disclaimer: Table data is randomly generated for illustrative purposes only. The information here is not a reflection of the actual market and does not constitute business, financial, or medical advice.
open in GitHub
<?php
 
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
use PowerComponents\LivewirePowerGrid\Button;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Exportable;
use PowerComponents\LivewirePowerGrid\Facades\Rule;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
use PowerComponents\LivewirePowerGrid\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\Traits\WithExport;
 
final class RadioButtonTable extends PowerGridComponent
{
use WithExport;
 
public function setUp(): array
{
$this->showRadioButton();
 
return [
Exportable::make('export')
->striped()
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV),
Header::make()
->showSearchInput(),
Footer::make()
->showPerPage()
->showRecordCount(),
];
}
 
public function datasource(): Builder
{
return User::query();
}
 
public function relationSearch(): array
{
return [];
}
 
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('name')
/** Example of custom column using a closure **/
->add('name_lower', fn (User $model) => strtolower(e($model->name)))
->add('email')
->add('created_at_formatted', fn (User $model) => Carbon::parse($model->created_at)->format('d/m/Y H:i:s'));
}
 
public function columns(): array
{
return [
Column::make('Id', 'id'),
Column::make('Name', 'name')
->sortable()
->searchable(),
 
Column::make('Email', 'email')
->sortable()
->searchable(),
 
Column::action('Action'),
];
}
 
public function actions(User $row): array
{
return [
Button::add('edit')
->slot('Edit: '.$row->id)
->id()
->class('pg-btn-white dark:ring-pg-primary-600 dark:border-pg-primary-600 dark:hover:bg-pg-primary-700 dark:ring-offset-pg-primary-800 dark:text-pg-primary-300 dark:bg-pg-primary-700')
->dispatch('edit', ['rowId' => $row->id]),
];
}
 
public function actionRules($row): array
{
return [
Rule::radio()
->when(fn ($row) => $row->id == $this->selectedRow)
->setAttribute('class', '!border-2 !border-fuchsia-500 bg-fuchsia-100 hover:!bg-fuchsia-100 dark:bg-fuchsia-800 dark:hover:bg-fuchsia-800'),
 
Rule::rows()
->setAttribute('wire:click', '$set(\'selectedRow\', '.$row->id.')'),
 
Rule::rows()
->setAttribute('class', '!cursor-pointer'),
 
];
}
}

Here you can find all relevant packages installed on this demo.

Name
Version
Description
laravel/framework
v10
The Laravel Framework.
openspout/openspout
v4.23.0
PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
power-components/livewire-powergrid
5.x-dev
PowerGrid generates Advanced Datatables using Laravel Livewire.