Apply filter by clicking on value in column
You can easily filter data in a table by clicking on a given value in cell, instead of opening filters and selecting value from there:
TextColumn::make('user.full_name') ->label('Person') ->tooltip('Filter by this person') ->disableClick() ->extraAttributes(function (Settlement $record) { return [ 'wire:click' => '$set("tableFilters.users.values", [' . $record->user_id . '])', 'class' => 'transition hover:text-primary-500 cursor-pointer', ]; }),
tableFilters.users.values - "users" is your filter name and depending on whether your filter allows multiple values to be selected values should be replaced by value and the field value should be passed as array or not.
If you need to set few filters at once, unfortunately you cannot set it inline, but instead you can extract it to dedicated method:
TextColumn::make('created_at') ->date() ->tooltip('Show only from this day') ->disableClick() ->extraAttributes(function ($record) { return [ 'wire:click' => 'filterFromDay("' . $record->created_at->format('Y-m-d') . '", "' . $record->created_at->format('Y-m-d') . '")', 'class' => 'transition hover:text-primary-500 cursor-pointer', ]; }),
and here is that method, which you should place in your ListRecords resource:
public function filterFromDay(string $from, string $until) : void{ $this->tableFilters['date_range']['created_from'] = $from; $this->tableFilters['date_range']['created_until'] = $until;}
No comments yet…