Filtering by clicking on column

I'm trying to set a table filter by clicking on the corresponding value in a table column using action() (as extraAttributes() gets escaped by blade). Using the following code
Tables\Columns\TextColumn::make('column.name')
->searchable()
->alignEnd()
->description(__('Some Description'), 'above')
->action(function (Model $record) {
$this->tableFilters['filterName'] = $record->value;
}),
Tables\Columns\TextColumn::make('column.name')
->searchable()
->alignEnd()
->description(__('Some Description'), 'above')
->action(function (Model $record) {
$this->tableFilters['filterName'] = $record->value;
}),
has no effect. The column (including the description, unfortunately) is clickable, and a request gets sent, but nothing else happens. Am I missing something? Do I have to tell the component to re-render? Setting a filter in html using wire:click="$set('tableFilters.filterName', [ '{{ $value }}' ])" does work fine, but is not achievable currently without overwriting the column templates and adding custom code.
2 Replies
Dan Harrin
Dan Harrin2y ago
maybe wrap the attribute value in new HtmlString() if you want to use extraattributes with action(), does a dd() run? try ->action(fn ($record) => Action::make('filterColumnName')->action(fn () => $this->tableFilters['filterName'] = $record->value))
josef
josefOP2y ago
No effect as well, and dd() is the same. If I find the time I'll investigate further.
->extraAttributes(static fn (Model $record): array => [
'wire:click' => new HtmlString("\$set('tableFilters.filterName', '{$record->value}')"),
]);
->extraAttributes(static fn (Model $record): array => [
'wire:click' => new HtmlString("\$set('tableFilters.filterName', '{$record->value}')"),
]);
does work though, thanks for the suggestion.
Want results from more Discord servers?
Add your server