Custom Layout
Top
ID
NAME
EMAIL
CREATED AT
Bottom
ID
|
↕
NAME
|
↕
EMAIL
|
↕
CREATED AT
|
---|---|---|---|
1
|
Luan
|
luanfreitasdev@fakemail.com
|
08/05/2024 20:50:03
|
2
|
Daniel
|
dansysanalyst@fakemail.com
|
08/05/2024 20:50:03
|
3
|
Claudio
|
claudio@fakemail.com
|
08/05/2024 20:50:03
|
4
|
Vitor
|
vitao@fakemail.com
|
08/05/2024 20:50:03
|
5
|
Tio Jobs
|
tiojobs@fakemail.com
|
08/05/2024 20:50:03
|
Top
Bottom
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
use App\Helpers\PowerGridThemes\TailwindStriped;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
use PowerComponents\LivewirePowerGrid\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
final class CustomLayoutTable extends PowerGridComponent
{
public function setUp(): array
{
return [
Header::make()
->showToggleColumns()
->showSearchInput()
->includeViewOnTop('components.header.view-on-top')
->includeViewOnBottom('components.header.view-on-bottom'),
Footer::make()
->showPerPage()
->showRecordCount()
->includeViewOnTop('components.bottom.view-on-top')
->includeViewOnBottom('components.bottom.view-on-bottom'),
];
}
public function datasource(): ?Builder
{
return User::query();
}
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('name')
->add('email')
->add('created_at_formatted', function (User $model) {
return Carbon::parse($model->created_at)->format('d/m/Y H:i:s');
})
->add('updated_at_formatted', function (User $model) {
return Carbon::parse($model->updated_at)->format('d/m/Y H:i:s');
});
}
public function columns(): array
{
return [
Column::add()
->title('ID')
->field('id'),
Column::add()
->title('NAME')
->field('name')
->sortable()
->searchable(),
Column::add()
->title('EMAIL')
->field('email')
->sortable()
->searchable(),
Column::add()
->title('CREATED AT')
->field('created_at_formatted', 'created_at')
->searchable()
->sortable(),
];
}
public function template(): ?string
{
return TailwindStriped::class;
}
}
Here you can find all relevant packages installed on this demo.
Name
|
Version
|
Description
|
---|---|---|
laravel/framework
|
v10
|
The Laravel Framework.
|
openspout/openspout
|
v4.23.1
|
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.
|