F
Filament15mo ago
rich06

Table recordUrl() to open a modal?

I have a custom page with a table which should open a view type modal when the row is clicked. I already have a ViewAction button defined for each row which loads the modal. However https://filamentphp.com/docs/3.x/tables/advanced#record-urls-clickable-rows only deals with opening a new page not a modal and I can't seem to configure $table->recordUrl() to open a modal... Anyone give me a pointer here? Thanks!
11 Replies
toeknee
toeknee15mo ago
Remove the view page from the pages array
rich06
rich06OP15mo ago
Thanks but this isn't a resource page it is a custom page with a table
toeknee
toeknee15mo ago
Ah, if you have the action just put a form on the action so it opens up instead of opening a page iwht the record url?
rich06
rich06OP15mo ago
Thanks again - please can you clarify a little (I am pretty new to Filament) - all I have currently is the custom page with a table definition which has a ViewAction defined that just loads a view blade file in a modal when the button is clicked. No form is used (yet!). I just want the same to happen when the user clicks on the row...
toeknee
toeknee15mo ago
Using V3 just use:
protected function getTableRecordAction(): ?string
{
return 'edit';
}
protected function getTableRecordAction(): ?string
{
return 'edit';
}
rich06
rich06OP15mo ago
I've added that function however it doesn't get called and the row is non-clickable. Do I need to add something to the blade/page class? The class extends Page implemenents HasTable and uses the InteractsWithTable trait..
toeknee
toeknee15mo ago
Change it to a ViewAction since edit will be expecting forms See if that works, but I am sure you still need to use the forms component for rendering a modal extends Component implements HasForms, HasTable { use InteractsWithForms, InteractsWithTable;
rich06
rich06OP15mo ago
The action defined on the table is already a ViewAction.. I have added the InteractsWithForms concern and the HasForms contract and the getTableRecordAction() is still not called and the rows are still not clickable Anyone?
toeknee
toeknee15mo ago
Please post your whole resource
Franck
Franck14mo ago
I dunno if you solved your problem, but I think I had the same issue. Here is how I solved it :
$table
->recordAction('name of your action')
->actions([
ViewAction::make('name of your action')
->label('')
->icon(null)
->modalContent(fn (Model $model): View => view(
'filament.resources.model-resource.pages.view',
[
'model' => $model,
],
))
], position: ActionsPosition::BeforeColumns)
$table
->recordAction('name of your action')
->actions([
ViewAction::make('name of your action')
->label('')
->icon(null)
->modalContent(fn (Model $model): View => view(
'filament.resources.model-resource.pages.view',
[
'model' => $model,
],
))
], position: ActionsPosition::BeforeColumns)
The trick is adding ->recordAction('name of your action') to table and put null & '' for icon and label to the ViewAction I didn't find another way to achieve this. Hope it helps
rich06
rich06OP14mo ago
Thanks for that tip - I will try it out when I get back to that development area
Want results from more Discord servers?
Add your server