F
Filament17mo ago
Jordy

Select Table record for bulk action on click

I want to select a record when clicked on, the CanSelectRecord trait only has a deselect all method, but no select one. I have tried
protected function getTableRecordActionUsing()
{
return fn($record) =>
$this->selectedTableRecords[] = $record;
}
protected function getTableRecordActionUsing()
{
return fn($record) =>
$this->selectedTableRecords[] = $record;
}
But this threw an error. Any help is appreciated
14 Replies
Dennis Koch
Dennis Koch17mo ago
But this threw an error.
And you didn't think it would help to share that error? I guess there is no $this and it needs to be the id and not the full record:
return fn ($livewire, $record) => $livewire->selectedTableRecords[] = $record->id;
return fn ($livewire, $record) => $livewire->selectedTableRecords[] = $record->id;
Jordy
JordyOP17mo ago
I will try your idea. original error:
Jordy
JordyOP17mo ago
where are you getting the $livewire from? it is not passed in automatically for me throws too few arguments
Dennis Koch
Dennis Koch17mo ago
Oh then you probably were right with $this
Jordy
JordyOP17mo ago
using the id as you said throws the same error in a different flavor: return fn($record) => $this->selectedTableRecords[] = $record->id;
Dennis Koch
Dennis Koch17mo ago
Right. It expects a method that returns an action. So you need to wrap your logic in another method or an action
Jordy
JordyOP17mo ago
swapped out getTableRecordActionUsing out for getTableRecordAction()
protected function getTableRecordAction()
{
return 'select';
}

public function select($record)
{
// dd($record);
$this->selectedTableRecords[] = $record;
}
protected function getTableRecordAction()
{
return 'select';
}

public function select($record)
{
// dd($record);
$this->selectedTableRecords[] = $record;
}
the dd does indeed dd the id of said record but when clicking now it does nothing- with no error, when diedumping dd($this->selectedTableRecords); it does dump the right id.. but it doesnt select it in the frontend
Dennis Koch
Dennis Koch17mo ago
I don’t really know if this is used in the Frontend since it’s alpine based. Guess you need to check out the source code
Jordy
JordyOP17mo ago
I do not have time to do so at the moment(this is for work haha), besides its more of a nice to have Will leave this open for a day or two in case someone else might want to look into it. Cheers for trying to help!
Alvaro Leon
Alvaro Leon17mo ago
Have you tried to use getAllSelectableTableRecordKeys() ?
Dennis Koch
Dennis Koch17mo ago
That’s for fetching them not setting
Alvaro Leon
Alvaro Leon17mo ago
Yeah but
php
$this->selectedTableRecords[] = getAllSelectableTableRecordKeys();
php
$this->selectedTableRecords[] = getAllSelectableTableRecordKeys();
should work?
Dennis Koch
Dennis Koch17mo ago
Not sure how that should work to select a specific record
Jordy
JordyOP17mo ago
I do not want to select all records.. And this has the same problem, it throws no error but does not select them either. It seems the table is not automatically updated when the selectedTableRecords array is changed. and I dont know what event is emitted normally, that should fix it.. I think
Want results from more Discord servers?
Add your server