Skip to content

Persist State โ€‹

Columns, filters, and sorting are persisted by default so the same view is restored on the next visit.

What is saved โ€‹

Default items: columns, filters, sorting.

Call persist() in setUp() to change the list or add a key prefix (for example per user). Call withoutPersist() to turn persistence off.

phpapp/Livewire/ProductTable.php
use PowerComponents\LivewirePowerGrid\PowerGridComponent;

class ProductTable extends PowerGridComponent
{
    public function setUp(): array
    {
        $this->persist( 
            tableItems: ['columns', 'filters', 'sorting'],
            prefix: (string) auth()->id()
        );

        return [];
    }
}
phpapp/Livewire/ProductTable.php
public function setUp(): array
{
    $this->withoutPersist(); 

    return [];
}

withoutPersist(['filters']) drops only those items from the default list.

The storage key is pg:{tableName}, or pg:{prefix}-{tableName} when a prefix is set. Set a unique $tableName.

Filter Builder state is separate: PowerGrid::filterBuilder()->persist(). See Filter Builder.

WARNING

Filters saved by PowerGrid 6 use a different bag shape. v7 does not restore them. Saved sorting and columns from v6 still apply. See the Upgrade Guide.

Driver โ€‹

Storage comes from persist_driver in configuration:

DriverDescription
cookiesDefault. Cookie, 5-year lifetime.
sessionLaravel session.
cacheLaravel cache. Set persist_driver_store to a cache store name, or leave it empty/null for the default store.

Override the driver for one table from boot():

phpapp/Livewire/ProductTable.php
use PowerComponents\LivewirePowerGrid\PowerGridComponent;

class ProductTable extends PowerGridComponent
{
    public function boot(): void
    {
        config(['livewire-powergrid.persist_driver' => 'session']);

        parent::boot();
    }
}

Created By Luan Freitas and @DanSysAnalyst