Tricks

Apply filter by clicking on value in column

Sep 10, 2022
studiowizjo
Table builder, Admin panel

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

No comments yet…