-
What i want?Accessing the selected record from bulk action in filament table and accessing the records from the form method Explanation of what i want to achieveWhen I click my bulk action, I open a new form in modal where the user can select which classroom the student will promoted based on the student's active classroom, so I need to get the student records to check they are in which class now, i hope it is clear 🙏 What did I do?Here's my code sneak peek Tables\Actions\BulkAction::make('promoted_students')
->form([
Forms\Components\Select::make('classroom_id')
->live()
//Here's what I did to try to accessing the selected records, but it doesn't work
->options(function(Collection $records){
return Classroom::all()
->pluck('classroom_name', 'id');
})
->searchable(['classroom_name'])
->default(fn($state) => $state)
->required(),
]), Where did I miss? thank you for letting me know, thank you for any helps 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
Try |
Beta Was this translation helpful? Give feedback.
-
hi Mate, here is the code, I hope you found it helpful, let us know if you found any issue Tables\Actions\BulkAction::make('buln_name')
->form([
\Filament\Forms\Components\Select::make('column_name')
->required(),
//.... another field here
])
->action(function(array $data, $livewire){
// dd($livewire->selectedTableRecords, $data);
// $data contains the form value, and the $livewire contains many stuff, but for getting only the selected data you can use $livewire->selectedTableRecords
}) |
Beta Was this translation helpful? Give feedback.
-
Cheers @christmex, so have I got this correct? Say in my table of languages I choose multiple records for bulk actioning. I want to have only those selected as options (either in Radio, Select, CheckboxList) in the modal form. And would I use the exact same method if I wanted to set the default? The following seems to work, just unsure if it's the advised method. Tables\Actions\BulkAction::make('merge_records')
->form([
\Filament\Forms\Components\Radio::make('master_id')
->label('Choose a master record to merge all selected records into')
->options(function($livewire) {
$options = $livewire->getSelectedTableRecords();
return $options->pluck('language', 'id'); // whatever columns are necessary
})
->default(function($livewire) {
$options = $livewire->getSelectedTableRecords();
return $options->first()->id; // if I wanted to have the first item pre-selected
})
->required(),
])
->action(function(array $data, $livewire){
// dd($livewire->selectedTableRecords, $data);
// $data contains the form value, and the $livewire contains many stuff, but for getting only the selected data you can use $livewire->selectedTableRecords
// DO THE MERGING STUFF
}) |
Beta Was this translation helpful? Give feedback.
-
How can I achieve, that each selected row is listet when selected, f.e. in a sidebar, without click to BulkAction-Button? |
Beta Was this translation helpful? Give feedback.
-
$livewire->getSelectedTableRecords() returns an empty array on my side... Illuminate\Database\Eloquent\Collection {#2182 ▼ // app\Filament\Resources\BookAdminResource\Pages\ListBookAdmins.php:32 any idea why ? |
Beta Was this translation helpful? Give feedback.
Try
$livewire->getSelectedTableRecords()