alpha
TableAction in the first row of a table
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.
3 replies