Files
filament/tests/src/Fixtures/Livewire/PostsTableWithGroupPersistedInSession.php
T
IGedeonandDan Harrin d8ef648e60 feat(tables): persist grouping in the user's session (#20165)
* feat(tables): persist grouping in the user's session

Add a `persistGroupInSession()` method to the table configuration,
mirroring the existing `persistSortInSession()` behavior, so a user's
chosen grouping is restored on their next visit.

The Livewire `updatedTableGroupColumn()` hook never fired because the
underlying property is `$tableGrouping` (Livewire resolves the hook as
`updatedTableGrouping()`). Renaming it fixes that dormant hook, which is
what both resets the page and now writes the grouping to the session.

* fix(tables): align grouping session persistence

---------

Co-authored-by: Dan Harrin <git@danharrin.com>
2026-09-04 09:27:10 +01:00

46 lines
1.3 KiB
PHP

<?php
namespace Filament\Tests\Fixtures\Livewire;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Tests\Fixtures\Models\Post;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Url;
use Livewire\Component;
class PostsTableWithGroupPersistedInSession extends Component implements HasActions, HasSchemas, Tables\Contracts\HasTable
{
use InteractsWithActions;
use InteractsWithSchemas;
use Tables\Concerns\InteractsWithTable;
#[Url(as: 'grouping')]
public ?string $tableGrouping = null;
public function table(Table $table): Table
{
return $table
->query(Post::query())
->groups(static fn () => [
Tables\Grouping\Group::make('title'),
Tables\Grouping\Group::make('author.name'),
])
->defaultGroup('title')
->persistGroupInSession()
->columns([
Tables\Columns\TextColumn::make('title')->sortable(),
Tables\Columns\TextColumn::make('author.name')->sortable(),
]);
}
public function render(): View
{
return view('livewire.table');
}
}