F
Filament12mo ago
urbycoz

Why doesn't my filter badge update when I apply a filter?

I've made a table with a filter. When I apply the filter (which seems to work fine) I would expect the badge on the filter icon to change from 0 to 1 but it doesn't. Here's my code: public function table(Table $table): Table { return $table ->query($this->getTableQuery()) ->deferLoading() ->columns($this->getTableColumns()) ->filters($this->getTableFilters()); } protected function getTableColumns(): array { return [ TextColumn::make('accountid') ->label('Account ID') ]; } protected function getTableFilters(): array { return [ Filter::make('accountid_filter') ->form([ TextInput::make('accountid')->label('Account ID'), ]) ->query(function (Builder $query, array $data): Builder { return $query->when( $data['accountid'], fn (Builder $query, $value): Builder => $query->where('accountid', 'ILIKE', "%{$value}%") ); }), ]; }
5 Replies
DrByte
DrByte12mo ago
Hmmm .. my filters seem to update the count on the badge to correctly indicate how many are applied. Is the problem specific to this filter? ie: have you tried another kind of filter, maybe on a different column (which you'd have to add to your table, because your example only shows that text column) Is the problem specific to this table? ie: do you have the same badge problem on other tables with filters on them?
urbycoz
urbycozOP12mo ago
Yeah I've made four similar tables with quite a number of columns - all text columns. All seem to have the same behaviour.
DrByte
DrByte12mo ago
I'd be inclined to create a fresh new one where the feature does work, and then start adding onto it to see what breaks it. If this is a standalone page, perhaps there's some traits that need importing to enable it?
urbycoz
urbycozOP12mo ago
Ok I'll try and do that. I've just been looking through the Filament source code. It seems the badge simply counts the number of filter indicators present and they don't appear when I apply my filter, even though the filtering itself seems to work ok. I've finally got it working by using: ->indicateUsing(function (array $data): ?string { if (! $data['accountid']) { return null; } return 'Account ID: '.$data['accountid']; }) I don't really understand why this is required but hey.
DrByte
DrByte12mo ago
Okay, ya, good point. Good job on digging into source: all kinds of answers are found there! It's good to set the indicateUsing() so that the user can see the badge of what filter is applied and optionally click the "x" next to it to clear that filter. And of course the side-benefit of the count.
Want results from more Discord servers?
Add your server