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
toeknee2y 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
lodekiOP2y ago
Thank you for the insight , though i get the error Method Filament\Tables\Actions\Action::fillDefaultData does not exist. .
toeknee
toeknee2y ago
updated
lodeki
lodekiOP2y ago
Meaning?
toeknee
toeknee2y ago
meaning I updated the existing code.
lodeki
lodekiOP2y ago
What's the method name in the updated code? Any idea please?
toeknee
toeknee2y 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
lodekiOP2y 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
toeknee2y 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
toeknee2y 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
lodekiOP2y ago
This one works .Thank you so much.
toeknee
toeknee2y ago
Just note, that will only get the pagnatied rows not ALL the rows.
lodeki
lodekiOP2y ago
Oh had forgotten that. And how do we get all of the rows.
toeknee
toeknee2y ago
I've litterally said it above ..... Here
lodeki
lodekiOP2y ago
oh my. Thank you.I really appreciate.

Did you find this page helpful?