Workflow
Persist

This example enables the Persist feature.

(This Table is a variation of the "Dish" example.)

XLSX
Csv
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
🍽️ All diets
419 kcal
29/06/2024
2
Albacore Tuna Melt
🍽️ All diets
530 kcal
05/07/2024
3
борщ
🍽️ All diets
Soup
835 kcal
10/07/2024
4
Bacalhau com natas
🍽️ All diets
Garnish
560 kcal
07/07/2024
5
Baba Ghanoush
🌱 Suitable for Vegans
Pasta
750 kcal
01/07/2024
6
Bacon Cheeseburger
🍽️ All diets
579 kcal
17/06/2024
7
Baked potato
🌱 Suitable for Vegans
Garnish
747 kcal
01/07/2024
8
Baklava
🥜 Suitable for Celiacs
Dessert
120 kcal
08/07/2024
9
Bangers and mash
🌱 Suitable for Vegans
138 kcal
21/06/2024
10
Black Pudding
🥜 Suitable for Celiacs
Pasta
660 kcal
19/06/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\Exportable;
use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
 
final class PersistTable extends DemoDishTable
{
public function setUp(): array
{
$this->persist(['columns', 'filters'], prefix: auth()->id ?? '');
 
return [
Exportable::make('export')
->striped()
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV),
 
Header::make()
->showToggleColumns()
->withoutLoading()
->showSearchInput(),
 
Footer::make()
->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

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

Name
Version
Description
laravel/framework
v11
The Laravel Framework.
livewire/livewire
v3.5.4
A front-end framework for Laravel.
openspout/openspout
v4.24.3
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.