F
Filament11mo ago
alpha

TableAction in the first row of a table

Does anyone knows, how I can show a TableAction only in the first row of a table? I've seen at https://filamentphp.com/docs/3.x/tables/columns/text#displaying-the-row-index that in a column the $rowLoop can be injected. However the injection does not work in a table action. Any workaround or idea? Thanks.
1 Reply
alpha
alphaOP10mo ago
Eventually, I came across a workaround. As a reminder, I needed to hide a TableAction in all rows except the first one. Since directly injecting $rowLoop into the hidden method of the TableAction wasn't possible, I approached it differently: I injected the Table and model record into the hidden method. Inside the closure, I accessed the LiveWire instance from the table. With that, I checked if the current row ID is equal to $livewire->cachedTableRecords[0]->id. This allowed me to display the action only for the first row and hide it for the rest: ->hidden(function (Table $table, Record $record) { // A workaround since FilamentPHP does not inject $rowLoop into TableAction $livewire = $table->getLivewire(); if ($record->id == $livewire->cachedTableRecords[0]->id) { return false; } return true; }) There may be a more elegant solution, but this approach resolved the issue for me. Hopefully, it can assist others facing similar challenges.
Want results from more Discord servers?
Add your server