ExportAction with dynamic exporter name based on the current row model value
I don't know if it is possible but i have a feeling it is
i have a custom list table with export action and for each row, i have different custom exporter defined. My problem is that ->exporter(<string>), takes only a string. The real issue is how to get the current value when the table is built so that i could build the correct exporter name.
16 Replies
Sounds like you shouldn't be using an exporter class? Exporter is for the current list which will be only application to this? Or you build multiple exporter classes?
I have built multiple exporters
So have a selector for the exporters opposed to trying to condition it on row, since an export is for the current list?
No i have a table list of data with custom actions on each row
The export varies depending on the row configuration
So if you have an action per row, you should be able to pass it in that way.
Provide your actions column
->actions([
ExportAction::make('export_list')
->exporter(AuthorExporter::class)
->color('info')
->label(false)
->tooltip(('admin.export'))
->icon('heroicon-o-arrow-down-tray')
->requiresConfirmation()
->modalHeading(('admin.export'))
->modalIcon('heroicon-o-information-circle')
->modalDescription(__('admin.confirm_message')),
])
AuthorExporter, i want to make this dynamic
Roughly
i got this error
Filament\Tables\Table::actions(): Argument #1 ($actions) must be of type Filament\Tables\Actions\ActionGroup|array, Closure given, called in /var/www/html/app/Livewire/ListTables.php on line 109
it weird though, i have checked the function, closure is allowed
Arghh
public function actions(array | ActionGroup $actions, ActionsPosition | string | Closure | null $position = null): static
for the 2nd argument it is allowed ๐คฆ๐ปโโ๏ธ
Not sure then tbh, you may need to do a PR for a closure to pass the record in.
Ok thx for help
Or just create multiple export actions with a visible on the current record?
You might actually be able to pass in $livewire and getRecord() ?
Sorry for the late answer,
For the first option, i don't think that will clean way to do this, i got around 15 exports to deal with.
For the second option, on which object are you referring to?
Well the digging continues ๐
, i found this on the net, so yea i'm experimenting
https://medium.com/@cameron_germein/things-i-wish-someone-had-explained-to-me-dependency-injection-in-laravel-filament-what-does-5dae3bbf8f23
Medium
Things I wish someone had explained to me: Dependency Injection in ...
As someone who is new to both Laravel and Filament, the one area I have struggled with the most is Dependency Injection. When it works, itโฆ
just for info, with this, the export button behave as i wanted โฎ๏ธ
Weirdly this does not work on the ImportAction
i'm marking it as solved, i have found a way using factories :cool_tofu: