Persist
This example enables the Persist feature.
(This Table is a variation of the "Dish" example.)
ID
Dish
Diet
Category
Price
Calories
Production date
In Stock
Action
ID
|
|
Dish
|
Diet
|
Category
|
Price
|
Calories
|
Production date
|
In Stock
|
Action
|
---|---|---|---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
1
|
|
Arkansas Possum Pie
|
🥜 Suitable for Celiacs
|
|
|
653 kcal
|
21/08/2024
|
|
|
2
|
|
Albacore Tuna Melt
|
🌱 Suitable for Vegans
|
|
|
266 kcal
|
28/08/2024
|
|
|
3
|
|
борщ
|
🥜 Suitable for Celiacs
|
|
|
402 kcal
|
28/08/2024
|
|
|
4
|
|
Bacalhau com natas
|
🥜 Suitable for Celiacs
|
|
|
164 kcal
|
06/08/2024
|
|
|
5
|
|
Baba Ghanoush
|
🌱 Suitable for Vegans
|
Pasta
|
|
534 kcal
|
04/08/2024
|
|
|
6
|
|
Bacon Cheeseburger
|
🍽️ All diets
|
|
|
101 kcal
|
11/08/2024
|
|
|
7
|
|
Baked potato
|
🍽️ All diets
|
|
|
272 kcal
|
09/08/2024
|
|
|
8
|
|
Baklava
|
🥜 Suitable for Celiacs
|
|
|
493 kcal
|
13/08/2024
|
|
|
9
|
|
Bangers and mash
|
🥜 Suitable for Celiacs
|
|
|
159 kcal
|
21/08/2024
|
|
|
10
|
|
Black Pudding
|
🌱 Suitable for Vegans
|
|
|
723 kcal
|
16/08/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\PersistTable; use App\Enums\Diet;use App\Livewire\Examples\DemoDishTable\DemoDishTable;use App\Models\Category;use App\Models\Chef;use Illuminate\Database\Eloquent\Builder;use PowerComponents\LivewirePowerGrid\Facades\Filter;use PowerComponents\LivewirePowerGrid\Facades\PowerGrid; final class PersistTable extends DemoDishTable{ public function setUp(): array { $this->persist(['columns', 'filters'], prefix: auth()->id ?? ''); return [ PowerGrid::header() ->showToggleColumns() ->withoutLoading() ->showSearchInput(), PowerGrid::footer() ->showPerPage() ->showRecordCount(), ]; } public function header(): array { return []; } public function filters(): array { return [ Filter::inputText('dish_name', 'dishes.name'), Filter::inputText('name') ->placeholder('Test') ->operators(['contains']), Filter::boolean('in_stock', 'in_stock') ->label('In stock', 'Out of stock'), Filter::enumSelect('diet', 'dishes.diet') ->dataSource(Diet::cases()) ->optionLabel('dishes.diet'), Filter::select('category_name', 'category_id') ->dataSource(Category::all()) ->optionLabel('name') ->optionValue('id'), Filter::select('chef_name', 'chef_id') ->depends(['category_id']) ->dataSource( fn ($depends) => Chef::query() ->when( isset($depends['category_id']), fn (Builder $query) => $query->whereRelation( 'categories', fn (Builder $builder) => $builder->where('id', $depends['category_id']) ) ) ->get() ) ->optionLabel('name') ->optionValue('id'), Filter::number('price_BRL', 'price'), Filter::datetimepicker('created_at_formatted', 'created_at') ->params([ 'timezone' => 'America/Sao_Paulo', ]), ]; }}
Code highlighting provided by Torchlight.dev