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
toeknee
toekneeโ€ข2mo ago
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?
n๐Ÿ…ฐ๐Ÿ…ณ๐Ÿ…ด๐Ÿ…ดm
I have built multiple exporters
toeknee
toekneeโ€ข2mo ago
So have a selector for the exporters opposed to trying to condition it on row, since an export is for the current list?
n๐Ÿ…ฐ๐Ÿ…ณ๐Ÿ…ด๐Ÿ…ดm
No i have a table list of data with custom actions on each row The export varies depending on the row configuration
toeknee
toekneeโ€ข2mo ago
So if you have an action per row, you should be able to pass it in that way. Provide your actions column
n๐Ÿ…ฐ๐Ÿ…ณ๐Ÿ…ด๐Ÿ…ดm
->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
toeknee
toekneeโ€ข2mo ago
->actions(function($record {
$class = $record->type === 1 ? AuthorExporter::class : 'Another Class');
return [
ExportAction::make('export_list')
->exporter($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')),
]}))
->actions(function($record {
$class = $record->type === 1 ? AuthorExporter::class : 'Another Class');
return [
ExportAction::make('export_list')
->exporter($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')),
]}))
Roughly
n๐Ÿ…ฐ๐Ÿ…ณ๐Ÿ…ด๐Ÿ…ดm
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
toeknee
toekneeโ€ข2mo ago
Arghh
n๐Ÿ…ฐ๐Ÿ…ณ๐Ÿ…ด๐Ÿ…ดm
public function actions(array | ActionGroup $actions, ActionsPosition | string | Closure | null $position = null): static for the 2nd argument it is allowed ๐Ÿคฆ๐Ÿปโ€โ™‚๏ธ
toeknee
toekneeโ€ข2mo ago
Not sure then tbh, you may need to do a PR for a closure to pass the record in.
n๐Ÿ…ฐ๐Ÿ…ณ๐Ÿ…ด๐Ÿ…ดm
Ok thx for help
toeknee
toekneeโ€ข2mo ago
Or just create multiple export actions with a visible on the current record? You might actually be able to pass in $livewire and getRecord() ?
n๐Ÿ…ฐ๐Ÿ…ณ๐Ÿ…ด๐Ÿ…ดm
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โ€ฆ
n๐Ÿ…ฐ๐Ÿ…ณ๐Ÿ…ด๐Ÿ…ดm
ExportAction::make('export_list')
->exporter(BaseExporter::class)
->beforeFormFilled(function ($record) {
/** @var ExportAction $exportAction */
$exportAction = $this->getMountedTableAction();
$exportAction->exporter($record->exporter_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')),
ExportAction::make('export_list')
->exporter(BaseExporter::class)
->beforeFormFilled(function ($record) {
/** @var ExportAction $exportAction */
$exportAction = $this->getMountedTableAction();
$exportAction->exporter($record->exporter_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')),
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:
Want results from more Discord servers?
Add your server