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