Workflow
Export
XLSX
Csv
ID
Name
Chef
Price
In Stock
Created At
1
Arkansas Possum Pie
-
95
1
05/04/2024
2
Albacore Tuna Melt
-
208
1
05/04/2024
3
борщ
Dan
277
1
05/04/2024
4
Bacalhau com natas
-
149
1
05/04/2024
5
Baba Ghanoush
-
56
0
05/04/2024
6
Bacon Cheeseburger
-
198
0
05/04/2024
7
Baked potato
-
206
1
05/04/2024
8
Baklava
-
67
0
05/04/2024
9
Bangers and mash
-
79
1
05/04/2024
10
Black Pudding
-
108
1
05/04/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\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 ExportTable extends PowerGridComponent
{
use WithExport;
 
public function setUp(): array
{
$this->showCheckBox();
 
return [
Exportable::make('export')
->striped()
->columnWidth([
2 => 30,
])
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV),
 
Header::make()
->showSearchInput(),
 
Footer::make()
->showPerPage()
->showRecordCount(),
];
}
 
public function datasource()
{
return Dish::with('category');
}
 
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('name')
->add('serving_at')
->add('chef_name', function (Dish $dish) {
return $dish->chef->name ?? '-';
})
->add('in_stock')
->add('in_stock_label', function ($entry) {
return $entry->in_stock ? 'sim' : 'não';
})
->add('created_at_formatted', function ($entry) {
return Carbon::parse($entry->created_at)->format('d/m/Y');
});
}
 
public function columns(): array
{
return [
Column::make('ID', 'id')
->searchable()
->sortable(),
 
Column::make('Name', 'name')
->searchable()
->hidden()
->visibleInExport(true)
->sortable(),
 
Column::make('Name', 'name')
->searchable()
->visibleInExport(false)
->sortable(),
 
Column::make(__('Chef'), 'chef_name', 'dishes.chef_name')
->searchable()
->placeholder('Chef placeholder')
->sortable(),
 
Column::make('Price', 'price')
->sortable(),
 
Column::make('In Stock', 'in_stock_label')
->field('in_stock'),
 
Column::make('Created At', 'created_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.