Access table filter in togglable

Is there a way around this error I'm getting when trying to access the filter inside toggleable Typed property Filament\Resources\Products\ListRecords::$cachedTableFilters must not be accessed before initialization I guess 'toggleable' form is setup before the table filters.
$table
->columns([
Tables\Columns\TextColumn::make('category')
->toggleable(fn (ListRecords $livewire) => $livewire->getCachedTableFilter('filter')->getState()['category_id'] ?? false)
])
->filters([
Tables\Filters\Filter::make('filter')
->form([
Forms\Components\Select::make('category_id')
->reactive()
->afterStateUpdated(fn ($state, \Closure $set) => $set('category_id', $state))
$table
->columns([
Tables\Columns\TextColumn::make('category')
->toggleable(fn (ListRecords $livewire) => $livewire->getCachedTableFilter('filter')->getState()['category_id'] ?? false)
])
->filters([
Tables\Filters\Filter::make('filter')
->form([
Forms\Components\Select::make('category_id')
->reactive()
->afterStateUpdated(fn ($state, \Closure $set) => $set('category_id', $state))
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
gizmojo
gizmojoOP2y ago
I couldn't get that to work but you got me searching and I found that I can call $livewire->cacheTableFilters() thanks That' s now working although the 'toggleable' form is not reactive
dusan8061
dusan80612y ago
Hey guys, I have widget Staff Widget. Depending on the role which user is logged in, I have to create pre-select filter in the table. So this is StaffWidget.php in widgets folder : protected function getTableColumns(): array { return [ Tables\Columns\TextColumn::make('name'), Tables\Columns\TextColumn::make('roles.name') ]; } and this is the code from UserResource.php : Forms\Components\TextInput::make('name')->required(), Forms\Components\TextInput::make('email')->required(), Forms\Components\Select::make('organisation')->relationship('organisation', 'name'), Bottom line, If I am logged in as a customer, role "customers" should be pre-selected on the Users overview page. Thanks in advance! @all
Want results from more Discord servers?
Add your server