F
Filament3mo ago
nowak

How to get all table records in header action

I want to add a header action for my admin panel resource table, where I need to send the records to a blade view to create a pdf export. What is the best way to get a Collection of the current tables records in a header action? I tried to do this:
->headerActions([
Action::make('downloadPdf')
->label('Download Pdf')
->icon('heroicon-o-arrow-down-tray')
->action(function (Collection $records, Table $table, Component $livewire) {
\Log::info('Pdf Export', ['Collection' => $records, 'Table Query' => $table->getQuery(), 'Component' => $livewire]);
}),
])
->headerActions([
Action::make('downloadPdf')
->label('Download Pdf')
->icon('heroicon-o-arrow-down-tray')
->action(function (Collection $records, Table $table, Component $livewire) {
\Log::info('Pdf Export', ['Collection' => $records, 'Table Query' => $table->getQuery(), 'Component' => $livewire]);
}),
])
But the looks don't show anything useful:
{"Collection":{"Illuminate\\Support\\Collection":[]},"Table Query":{"Illuminate\\Database\\Eloquent\\Builder":[]},"Component":{"App\\Filament\\Resources\\GroupOrderManagementResource\\Pages\\ListGroupOrderManagement":{"mountedActions":[],"mountedActionsArguments":[],"mountedActionsData":[],"defaultAction":null,"defaultActionArguments":null,"componentFileAttachments":[],"mountedFormComponentActions":[],"mountedFormComponentActionsArguments":[],"mountedFormComponentActionsData":[],"mountedFormComponentActionsComponents":[],"mountedInfolistActions":[],"mountedInfolistActionsData":[],"mountedInfolistActionsComponent":null,"mountedInfolistActionsInfolist":null,"isTableReordering":false,"tableFilters":{"status":{"show_declined":false}},"tableGrouping":null,"tableGroupingDirection":null,"tableSearch":"","tableSortColumn":null,"tableSortDirection":null,"activeTab":"dinner","isTableLoaded":false,"tableRecordsPerPage":10,"tableColumnSearches":[],"toggledTableColumns":[],"mountedTableActions":["downloadPdf"],"mountedTableActionsData":[[]],"mountedTableActionsArguments":[[],[]],"mountedTableActionRecord":null,"defaultTableAction":[],"defaultTableActionArguments":[],"defaultTableActionRecord":[],"selectedTableRecords":[],"mountedTableBulkAction":null,"mountedTableBulkActionData":[],"tableDeferredFilters":null,"paginators":{"page":1}}}}
{"Collection":{"Illuminate\\Support\\Collection":[]},"Table Query":{"Illuminate\\Database\\Eloquent\\Builder":[]},"Component":{"App\\Filament\\Resources\\GroupOrderManagementResource\\Pages\\ListGroupOrderManagement":{"mountedActions":[],"mountedActionsArguments":[],"mountedActionsData":[],"defaultAction":null,"defaultActionArguments":null,"componentFileAttachments":[],"mountedFormComponentActions":[],"mountedFormComponentActionsArguments":[],"mountedFormComponentActionsData":[],"mountedFormComponentActionsComponents":[],"mountedInfolistActions":[],"mountedInfolistActionsData":[],"mountedInfolistActionsComponent":null,"mountedInfolistActionsInfolist":null,"isTableReordering":false,"tableFilters":{"status":{"show_declined":false}},"tableGrouping":null,"tableGroupingDirection":null,"tableSearch":"","tableSortColumn":null,"tableSortDirection":null,"activeTab":"dinner","isTableLoaded":false,"tableRecordsPerPage":10,"tableColumnSearches":[],"toggledTableColumns":[],"mountedTableActions":["downloadPdf"],"mountedTableActionsData":[[]],"mountedTableActionsArguments":[[],[]],"mountedTableActionRecord":null,"defaultTableAction":[],"defaultTableActionArguments":[],"defaultTableActionRecord":[],"selectedTableRecords":[],"mountedTableBulkAction":null,"mountedTableBulkActionData":[],"tableDeferredFilters":null,"paginators":{"page":1}}}}
Solution:
$livewire->getFilteredTableQuery()->get()
$livewire->getFilteredTableQuery()->get()
Could be worth a try...
Jump to solution
2 Replies
Solution
dissto
dissto3mo ago
$livewire->getFilteredTableQuery()->get()
$livewire->getFilteredTableQuery()->get()
Could be worth a try
nowak
nowak3mo ago
Thank you! Exactly what I needed. I also found this:
$livewire->getTableRecords()
$livewire->getTableRecords()
Which I think includes all rows, not just the paginated row.