Workflow
Batch Export
ID
Dish
Chef
Diet
Category
Price
Sales price
Calories
In Stock
Kitchen
Production date
1
Arkansas Possum Pie
-
🌱 Suitable for Vegans
Meat
R$ 274,00
R$ 315,10
664 kcal
BA
09/02/2024
2
Albacore Tuna Melt
-
πŸ₯œ Suitable for Celiacs
Fish
R$ 66,00
R$ 75,90
833 kcal
RJ
05/02/2024
3
Π±ΠΎΡ€Ρ‰
Dan
🍽️ All diets
Soup
R$ 125,00
R$ 143,75
339 kcal
SP
22/02/2024
4
Bacalhau com natas
-
🍽️ All diets
Fish
R$ 57,00
R$ 65,55
760 kcal
RJ
21/02/2024
5
Baba Ghanoush
-
πŸ₯œ Suitable for Celiacs
Soup
R$ 134,00
R$ 154,10
250 kcal
BA
29/01/2024
6
Bacon Cheeseburger
-
🍽️ All diets
Pie
R$ 199,00
R$ 228,85
320 kcal
MG
07/02/2024
7
Baked potato
-
πŸ₯œ Suitable for Celiacs
Meat
R$ 195,00
R$ 224,25
365 kcal
SP
09/02/2024
8
Baklava
-
πŸ₯œ Suitable for Celiacs
Meat
R$ 193,00
R$ 221,95
189 kcal
RJ
01/02/2024
9
Bangers and mash
-
🌱 Suitable for Vegans
Soup
R$ 69,00
R$ 79,35
351 kcal
BA
23/01/2024
10
Black Pudding
-
🌱 Suitable for Vegans
Garnish
R$ 140,00
R$ 161,00
589 kcal
MG
09/02/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.
open in GitHub
<?php
 
use App\Models\Dish;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Exportable;
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 BatchExportTable extends PowerGridComponent
{
use WithExport;
 
public string $sortField = 'dishes.id';
 
public function setUp(): array
{
$this->showCheckBox();
 
return [
Exportable::make('export')
->striped()
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV)
->queues(6)
->onQueue('my-dishes')
->onConnection('redis'),
 
Header::make()
->showSearchInput(),
 
Footer::make()
->showPerPage()
->showRecordCount(),
];
}
 
public function datasource(): ?Builder
{
return Dish::with(['category:id,name', 'kitchen']);
}
 
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('serving_at')
->add('chef_name', function (Dish $dish) {
return $dish->chef->name ?? '-';
})
->add('dish_name', function (Dish $dish) {
return $dish->name;
})
->add('calories', function (Dish $dish) {
return $dish->calories.' kcal';
})
->add('category_id', function (Dish $dish) {
return $dish->category_id;
})
->add('category.name')
->add('kitchen_id', function (Dish $dish) {
return $dish->kitchen_id;
})
->add('kitchen.description')
->add('price')
->add('price_BRL', function (Dish $dish) {
return 'R$ '.number_format($dish->price, 2, ',', '.'); //R$ 1.000,00
})
->add('sales_price')
->add('sales_price_BRL', function (Dish $dish) {
$sales_price = $dish->price + ($dish->price * 0.15);
 
return 'R$ '.number_format($sales_price, 2, ',', '.'); //R$ 1.000,00
})
->add('in_stock')
->add('in_stock_label', function (Dish $dish) {
return $dish->in_stock ? 'yes' : 'no';
})
 
->add('diet', function (Dish $dish) {
return \App\Enums\Diet::from($dish->diet)->labels();
})
 
->add('produced_at')
->add('produced_at_formatted', function (Dish $dish) {
return Carbon::parse($dish->produced_at)->format('d/m/Y');
});
}
 
public function columns(): array
{
return [
Column::make('ID', 'id', 'dishes.id')
->searchable()
->sortable(),
 
Column::make(__('Dish'), 'dish_name', 'dishes.name')
->searchable()
->placeholder('Dish placeholder')
->sortable(),
 
Column::make(__('Chef'), 'chef_name', 'dishes.chef_name')
->searchable()
->placeholder('Chef placeholder')
->sortable(),
 
Column::make('Diet', 'diet', 'dishes.diet'),
 
Column::make(__('Category'), 'category.name')
->placeholder('Category place..'),
 
Column::make(__('Price'), 'price_BRL'),
 
Column::make(__('Sales price'), 'sales_price_BRL'),
 
Column::make(__('Calories'), 'calories')
->sortable(),
 
Column::make(__('In Stock'), 'in_stock')
->toggleable(true, 'yes', 'no')
->sortable(),
 
Column::make(__('Kitchen'), 'kitchen.description', 'kitchen_id')
->sortable(),
 
Column::make(__('Production date'), 'produced_at_formatted'),
];
}
}

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.