F
Filament7mo ago
lodeki

Get table data from header action.

I have a custom table header action .How can I access the table data from the action() method of the table header action? Tried to access it from the $livewire property like so
action(function (Component $livewire) {
dd($livewire);
})
action(function (Component $livewire) {
dd($livewire);
})
but can't really get it .
Solution:
this will get all from the fitlered table: ```php Action::make('test') ->action(fn($data, $livewire) => dd($livewire->getFilteredTableQuery()->get())),...
Jump to solution
15 Replies
toeknee
toeknee7mo ago
Looking at how AlperenErsoy did it with filamentexport:
->action(static function ($action, $data) {
$records = $action->getRecords();
});
->action(static function ($action, $data) {
$records = $action->getRecords();
});
lodeki
lodeki7mo ago
Thank you for the insight , though i get the error Method Filament\Tables\Actions\Action::fillDefaultData does not exist. .
toeknee
toeknee7mo ago
updated
lodeki
lodeki7mo ago
Meaning?
toeknee
toeknee7mo ago
meaning I updated the existing code.
lodeki
lodeki7mo ago
What's the method name in the updated code? Any idea please?
toeknee
toeknee7mo ago
It'sthe code above, just copy it
->action(static function ($action, $data) {
$records = $action->getRecords();
});
->action(static function ($action, $data) {
$records = $action->getRecords();
});
I've just remove the fillDefaultData
lodeki
lodeki7mo ago
Sorry but still experiencing the same error but this time with the getRecords() method as below
Method Filament\Tables\Actions\Action::getRecords does not exist.
Method Filament\Tables\Actions\Action::getRecords does not exist.
toeknee
toeknee7mo ago
What about $this->getTableRecords() ? I'm not sure of the top of my head with V3 but these are along the lines that I would expect
Action::make('test')
->action(fn($data, $livewire) => dd($livewire->getTableRecords())),
Action::make('test')
->action(fn($data, $livewire) => dd($livewire->getTableRecords())),
Will give you the filtered/records displayed
Solution
toeknee
toeknee7mo ago
this will get all from the fitlered table:
Action::make('test')
->action(fn($data, $livewire) => dd($livewire->getFilteredTableQuery()->get())),
Action::make('test')
->action(fn($data, $livewire) => dd($livewire->getFilteredTableQuery()->get())),
lodeki
lodeki7mo ago
This one works .Thank you so much.
toeknee
toeknee7mo ago
Just note, that will only get the pagnatied rows not ALL the rows.
lodeki
lodeki7mo ago
Oh had forgotten that. And how do we get all of the rows.
toeknee
toeknee7mo ago
I've litterally said it above ..... Here
lodeki
lodeki7mo ago
oh my. Thank you.I really appreciate.