Workflow
Custom Theme Striped

This component uses the Custom Theme TailwindStriped.

You can find its source code in our GitHub Repository.

ID
Name
Price
In Stock
Created At
1
Arkansas Possum Pie
118,08 €
No
26/09/2024
2
Albacore Tuna Melt
132,75 €
No
07/10/2024
3
борщ
100,19 €
Yes
26/09/2024
4
Bacalhau com natas
208,60 €
No
29/09/2024
5
Baba Ghanoush
183,81 €
No
03/10/2024
6
Bacon Cheeseburger
137,48 €
No
11/09/2024
7
Baked potato
189,66 €
Yes
03/10/2024
8
Baklava
161,92 €
Yes
12/10/2024
9
Bangers and mash
214,04 €
Yes
03/10/2024
10
Black Pudding
116,13 €
Yes
03/10/2024
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.
<?php
 
namespace App\Livewire\Examples\CustomThemeStripedTable;
 
use App\Helpers\PowerGridThemes\TailwindStriped;
use App\Models\Dish;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Carbon;
use Illuminate\Support\Number;
use Livewire\Attributes\On;
use PowerComponents\LivewirePowerGrid\Column;
 
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
 
class CustomThemeStripedTable extends PowerGridComponent
{
public string $tableName = 'custom-theme-striped-table';
 
public function setUp(): array
{
return [
PowerGrid::header()
->showSearchInput(),
 
PowerGrid::footer()
->showPerPage()
->showRecordCount(),
];
}
 
public function datasource(): ?Builder
{
return Dish::query()
->join('categories as newCategories', function ($categories) {
$categories->on('dishes.category_id', '=', 'newCategories.id');
})
->select('dishes.*', 'newCategories.name as category_name')
->toBase();
}
 
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('name')
->add('price')
->add('price_in_eur', fn ($dish) => Number::currency($dish->price, in: 'EUR', locale: 'pt_PT'))
->add('in_stock', fn ($dish) => $dish->in_stock ? 'Yes' : 'No')
->add('created_at_formatted', fn ($dish) => Carbon::parse($dish->created_at)->format('d/m/Y'));
}
 
public function columns(): array
{
return [
 
Column::make('ID', 'id')
->searchable()
->sortable(),
 
Column::make('Name', 'name')
->bodyAttribute('!text-wrap')
->searchable()
->sortable(),
 
Column::make('Price', 'price_in_eur', 'price')
->searchable()
->sortable(),
 
Column::make('In Stock', 'in_stock'),
 
Column::make('Created At', 'created_at_formatted'),
];
}
 
#[On('edit')]
public function edit(int $dishId): void
{
$this->js('alert(' . $dishId . ')');
}
 
public function customThemeClass(): ?string
{
return TailwindStriped::class;
}
}
Code highlighting provided by Torchlight.dev