F
Filament15mo ago
roni

how to make filament table row clickable to model view page

I have a search Page which used filament table for user. I also have UserResource for users. How to make table row clickable to user view page.
class Search extends Page implements Tables\Contracts\HasTable
{
use Tables\Concerns\InteractsWithTable;
...
protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name')
->searchable()
->placeholder('-'),
Tables\Columns\TextColumn::make('contact_number')
->searchable(),
];
}

protected function getTableRecordActionUsing(): ?Closure
{
// I need help here, how to make it open ViewUser page in UserResource.
}
protected function getTableQuery(): Builder
{
return User::query()
->whereIn('pincode', $pincode_array);
}
}
class Search extends Page implements Tables\Contracts\HasTable
{
use Tables\Concerns\InteractsWithTable;
...
protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name')
->searchable()
->placeholder('-'),
Tables\Columns\TextColumn::make('contact_number')
->searchable(),
];
}

protected function getTableRecordActionUsing(): ?Closure
{
// I need help here, how to make it open ViewUser page in UserResource.
}
protected function getTableQuery(): Builder
{
return User::query()
->whereIn('pincode', $pincode_array);
}
}
search.blade.php
<x-filament::page>
<form wire:submit.prevent="submit">
{{ $this->form }}
</br>
<x-filament::button type="submit">Search</x-filament::button>
</form>

<div>
{{ $this->table }}
</div>
</x-filament::page>
<x-filament::page>
<form wire:submit.prevent="submit">
{{ $this->form }}
</br>
<x-filament::button type="submit">Search</x-filament::button>
</form>

<div>
{{ $this->table }}
</div>
</x-filament::page>
2 Replies
Dan Harrin
Dan Harrin15mo ago
instead of getTableRecordActionUsing you probably want getTableRecordUrlUsing fn ($record) => UserResource::getUrl('view', ['record' => $record])
roni
roni15mo ago
Thanks Dan, it works.