How to get selected record from table in header action?

I want to make header action that can collect the selected record link in bulkaction and send all value to custom view in new tab, i have search in doc but i still not find any clue, this is my code ->headerActions([ Action::make('Label') ->url(fn () => route('label', ['selected_records' => ['33', '34']])) ->openUrlInNewTab(), ]) i want selected_records is array from selected record like bulkaction, Thank you
Solution:
I have found a simple solution for this problem, I use notification for opening bulk action in new tab, this is my code ```BulkAction::make('Label Barcode') ->label('Label Barcode') ->action(function ($records) {...
Jump to solution
4 Replies
Patrick Boivin
Patrick Boivin17mo ago
Just curious: why not use a BulkAction?
ariftography
ariftographyOP17mo ago
I already use bulkaction, but i can not find how to open it in new tab, i just success to open it in same tab, this is my code now in resource ''' BulkAction::make('Label Barcode') ->label('Label Barcode') ->action(function ($records) { $selectedRecordIds = $records->pluck('id')->toArray(); $route = route('label', ['selected_records' => $selectedRecordIds]); return redirect($route); }) ->deselectRecordsAfterCompletion(), ''' in model ''' public function labelBarcode(Request $request) { $selectedRecordIds = $request->input('selected_records', []); $selectedRecords = AsetGuna::with('NamaAset')->with('lokasi') ->whereIn('id', $selectedRecordIds)->get(); return view('filament.label')->with('selectedRecords', $selectedRecords); } ''' in route ''' Route::get('label', [AsetGuna::class, 'labelbarcode'])->name('label'); ''' have you any experience to open bulkaction in new tab?
Patrick Boivin
Patrick Boivin17mo ago
I don't think you can redirect in a new tab unfortunately Maybe you can emit a Livewire event and add some JS code to open the new tab?
Solution
ariftography
ariftography16mo ago
I have found a simple solution for this problem, I use notification for opening bulk action in new tab, this is my code
BulkAction::make('Label Barcode')
->label('Label Barcode')
->action(function ($records) {

$selectedRecordIds = $records->pluck('id')->implode(',');

Notification::make()
->title('Apakah Anda yakin akan mencetak label ini?')
->success()
->persistent()
->actions([
Action::make('ya')
->button()
->url(route('label', $selectedRecordIds), shouldOpenInNewTab: true)
->close(),

])
->send();
}),
BulkAction::make('Label Barcode')
->label('Label Barcode')
->action(function ($records) {

$selectedRecordIds = $records->pluck('id')->implode(',');

Notification::make()
->title('Apakah Anda yakin akan mencetak label ini?')
->success()
->persistent()
->actions([
Action::make('ya')
->button()
->url(route('label', $selectedRecordIds), shouldOpenInNewTab: true)
->close(),

])
->send();
}),
Want results from more Discord servers?
Add your server