Filament Table Row Click: Open Modal Window View

Filament Table has a feature of clicking on the row and landing on the Edit page. What if you want to change that and instead open a modal with the record data? Let's do that using Table Actions.

modal view


By default, the table row has a link. First, we must disable the link by setting recordUrl to null in the table.

class PostResource extends Resource
{
// ...
 
public static function table(Table $table): Table
{
return $table
->columns(...)
->filters(...)
->actions(...)
->bulkActions(...)
->recordUrl(null);
}
 
// ...
}

Now, a method recordAction is used to set the action for a whole row. In this method, we can pass a View Action class.

use Filament\Tables;
 
class PostResource extends Resource
{
// ...
 
public static function table(Table $table): Table
{
return $table
->columns(...)
->filters(...)
->actions(...)
->bulkActions(...)
->recordAction(Tables\Actions\ViewAction::class)
->recordUrl(null);
}
 
// ...
}

And now, when clicked on a row, the view action will be called, and a modal with a records view will be opened.

Notice: don't forget that when creating a Resource, you also need to create a View. If you forgot to create, you can create a View to an existing Resource.


If you want more Filament examples, you can find more real-life projects on our FilamentExamples.com.

avatar

Hello,

is it also possible to add an EditAction (Header or Footer) in the ViewAction? Thanks

BR Thomas

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 59 courses (1057 lessons, total 42 h 44 min)
  • 78 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials