Workflow
Export
XLSX
Csv
ID
Name
Chef
Price
In Stock
Created At
1
Arkansas Possum Pie
-
224
1
18/03/2024
2
Albacore Tuna Melt
-
113
1
18/03/2024
3
борщ
Dan
204
1
18/03/2024
4
Bacalhau com natas
-
56
0
18/03/2024
5
Baba Ghanoush
-
90
1
18/03/2024
6
Bacon Cheeseburger
-
62
1
18/03/2024
7
Baked potato
-
167
1
18/03/2024
8
Baklava
-
140
0
18/03/2024
9
Bangers and mash
-
75
0
18/03/2024
10
Black Pudding
-
177
0
18/03/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
10
The Laravel Framework.
openspout/openspout
4.x-dev
PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
power-components/livewire-powergrid
dev-livewire-main
PowerGrid generates Advanced Datatables using Laravel Livewire.