Get table records

i want to get those records show in the filament table even apply filters in closure functions
9 Replies
Dennis Koch
Dennis Koch4d ago
Try providing some more info
Muhammad Umar Mughal Azeemi
In a Filament table resource, I have created an action button on the list page. I want to export the data displayed in the table, and for that, I need to get the table data in a custom export class. The challenge is to ensure that when filters are applied to the table (e.g., if 5 users are displayed initially and after applying filters, only 2 users remain), the custom export should include only the 2 users shown after filtering. This means that the export should include all the records currently displayed in the table, whether filters are applied or not.
Dennis Koch
Dennis Koch4d ago
You should be able to access those through fn ($livewire) => $livewire->getFilteredTableQuery()->get()
Muhammad Umar Mughal Azeemi
its working but if i same thing in UserResources Main File. How i can perform this task getFilteredTableQuery() i use this in UserResource main file and it not working ($livewire) => $livewire->getFilteredTableQuery()->get() Tables\Actions\Action::make('exports') ->label('Export') ->icon('heroicon-s-download') ->color('success') ->action(function ($livewire) : void{ dd($livewire->getFilteredTableQuery()->get()); }),
Dennis Koch
Dennis Koch3d ago
What kind of action is that? Table header action? Please format your code with backticks (see #✅┊rules )
Muhammad Umar Mughal Azeemi
yes i use in table header action
Tables\Actions\Action::make('exports')
->label('Export')
->icon('heroicon-s-download')
->color('success')
->action(function($livewire)
{
$livewire
->getFilteredTableQuery()
->get();
})
Tables\Actions\Action::make('exports')
->label('Export')
->icon('heroicon-s-download')
->color('success')
->action(function($livewire)
{
$livewire
->getFilteredTableQuery()
->get();
})
Dennis Koch
Dennis Koch3d ago
Hm, I am not sure then. Does it return an empty collection? Try debugging $livewire->getFilteredTableQuery() and see what the actual query is
Muhammad Umar Mughal Azeemi
no empty collection it return the error getFilteredTableQuery() method does exist in userresources/pages/ListUser.php
Dennis Koch
Dennis Koch3d ago
Hm. Check the existing methods for the ListRecords class. Maybe I made a typo

Did you find this page helpful?