F
Filamentβ€’7mo ago
Samus_Aran

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
Samus_Aran
Samus_AranOPβ€’7mo ago
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 πŸ˜„
awcodes
awcodesβ€’7mo ago
ViewAction::make()?
Samus_Aran
Samus_AranOPβ€’7mo ago
@awcodes the recordAction() method only accepts a string. I figured out that this is working:
->actions([
ViewAction::make()
])
->recordAction('view')
->actions([
ViewAction::make()
])
->recordAction('view')
But now I have a clickable row AND a 'View' Action link on the right.
awcodes
awcodesβ€’7mo ago
i'm pretty sure that if you have a view action registered in the actions that the view is the default record action
Samus_Aran
Samus_AranOPβ€’7mo ago
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:
ViewAction::make()
->hiddenLabel(true)
->icon(false)
ViewAction::make()
->hiddenLabel(true)
->icon(false)
But then I have some whitespace, because Filament still renders the table column for the actions πŸ˜„
awcodes
awcodesβ€’7mo ago
try with just ->hidden()
Samus_Aran
Samus_AranOPβ€’7mo ago
I did that already. Then clicking the row doesn't work anymore. It disables the action entirely
awcodes
awcodesβ€’7mo ago
this might work: ->recordAction(fn ($record) => static::getUrl('view', ['record' => $record]))
Samus_Aran
Samus_AranOPβ€’7mo ago
let me try this...
awcodes
awcodesβ€’7mo ago
you have to have a view page registered and a view page class for it to work though.
Samus_Aran
Samus_AranOPβ€’7mo ago
@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')"
awcodes
awcodesβ€’7mo ago
ah, do ->recordUrl() instead
Samus_Aran
Samus_AranOPβ€’7mo ago
@awcodes haha yes, this works πŸ˜„ But then it doesn't open in a modal πŸ˜„
awcodes
awcodesβ€’7mo ago
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
Samus_Aran
Samus_AranOPβ€’7mo ago
@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
Want results from more Discord servers?
Add your server