Workflow
Defer Loading
PLEASE WAIT: Page loading was slowed down for demonstration purposes.

This example enables the Defer Loading feature, displaying a custom spinner Blade Component instead of the default "Loading" message.

ID
Name
Created At
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\DeferLoadingTable;

use App\Models\Dish;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
use PowerComponents\LivewirePowerGrid\Column;

use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\PowerGridFields;

final class DeferLoadingTable extends PowerGridComponent
{
    public string $tableName = 'defer-loading-table';

    public bool $deferLoading = true;

    public string $loadingComponent = 'components.my-custom-loading';

    public function setUp(): array
    {
        return [

            PowerGrid::header()
                ->withoutLoading()
                ->showSearchInput(),

            PowerGrid::footer()
                ->showRecordCount(),
        ];
    }

    public function datasource(): ?Builder
    {
        return Dish::query();
    }

    public function fields(): PowerGridFields
    {
        return PowerGrid::fields()
            ->add('id')
            ->add('name')
            ->add('created_at_formatted', fn ($dish) => Carbon::parse($dish->created_at)->format('d/m/Y'));
    }

    public function columns(): array
    {
        return [
            Column::make('ID', 'id'),

            Column::make('Name', 'name'),

            Column::make('Created At', 'created_at_formatted'),
        ];
    }

    public function hydrate(): void
    {
        sleep(20);  // ⏳ Purposefully slow down the Component loading for demonstration purposes.
    }
}