F
Filamentβ€’5mo ago
Wannes

Get all sortable columns of table

Hi, I'm trying to create some automated tests. So basically I want to execute all these tests (https://filamentphp.com/docs/3.x/tables/testing), but I'm trying to automate them. Now I'm wondering how I could get all the columns of my table which I specified with ->sortable() in my resource. Than I can just create a loop and execute my tests based on the fields.
Solution:
return collect($this->getResourceTableColumns())
->filter(fn ($column) => $column->isSortable());
return collect($this->getResourceTableColumns())
->filter(fn ($column) => $column->isSortable());
...
Jump to solution
6 Replies
BlackShadow
BlackShadowβ€’4mo ago
Did you figure it out?
Wannes
Wannesβ€’4mo ago
No, unfortunately not
BlackShadow
BlackShadowβ€’4mo ago
$livewire = app('livewire')->new(ListRecords::class);

return BlogResource::table(new Table($livewire))->getColumns();
$livewire = app('livewire')->new(ListRecords::class);

return BlogResource::table(new Table($livewire))->getColumns();
Mark Chaney
Mark Chaneyβ€’4mo ago
that will just get all columns though and not all sortable columns, right? Probably like us, wants to make sure sorting a column or searching on a table doesnt throw any errors.
Solution
BlackShadow
BlackShadowβ€’4mo ago
return collect($this->getResourceTableColumns())
->filter(fn ($column) => $column->isSortable());
return collect($this->getResourceTableColumns())
->filter(fn ($column) => $column->isSortable());
Wannes
Wannesβ€’4mo ago
Awesome, thanks! πŸ™