Use recordAction() In a Table Widget
Hello! I have a TableWidget that displays all invoices that I have for an OrderResource on it's view page.
The Invoices don't have a page on their own. I created an Action that opens a modal. I can add this action to the actions() method of my table, but this will render a "View" Link on each table row.
Instead I simply want the whole table row to be clickable. I know this can be done with the method ->recordAction(), but I can't seem to get it working. Can someboy explain to me how to wire up my Table Row Action so that I can use it with ->recordAction()?
15 Replies
I can do ->recordAction(Table\Actions\ViewAction::class) but then I get an Exception that a view() method is missing on my component. And I don't know what I should put into that method π
ViewAction::make()?
@awcodes the recordAction() method only accepts a string. I figured out that this is working:
But now I have a clickable row AND a 'View' Action link on the right.
i'm pretty sure that if you have a view action registered in the actions that the view is the default record action
Yes, I have this default behaviour out of the box on all tables on Resource List Views. But I am in a TableWidget on the view page of a different resource...
@awcodes I could make my View Action on the right de facto invisible like this:
But then I have some whitespace, because Filament still renders the table column for the actions π
try with just ->hidden()
I did that already. Then clicking the row doesn't work anymore. It disables the action entirely
this might work:
->recordAction(fn ($record) => static::getUrl('view', ['record' => $record]))
let me try this...
you have to have a view page registered and a view page class for it to work though.
@awcodes okay, I added a view page for my invoices and checked that it is working. I then added
->recordAction(fn ($record) => InvoiceResource::getUrl('view', ['record' => $record]))
to my table which results in an Alpine Expression when I click the table row:
Alpine Expression Error: Unexpected token ':'
Expression: "$wire.http://sampleapp.test/projects/1/invoices/1('1')"ah, do ->recordUrl() instead
@awcodes haha yes, this works π But then it doesn't open in a modal π
well, then yea, that's going to require an actual action
you could always just target the ViewAction or the actions column, and hide it with css, if you don't need it
@awcodes Yes it looks like it. I am currently toying around with this and it seems like whatever Action I put into recordAction() needs to be also present in actions() of the table. So it seems that I need to hide it with CSS