Group records in sort order

Hi, Tuto - I have been watching your vet clinic streams lately and have a question. When we group a table, we can dispaly it in ASC or DESC order. But can we add the third parameter - 'sort_order' to the dropdown? Filament offers sorting out of the box and grouping by sort order by default would be nice in one of my projects. Thanks!
2 Replies
tuto1902
tuto190211mo ago
Have you tried customizing the group query? I think you can add ->orderBy() to the query and that will allow you to have default sorting on your group. I hope that answers your question https://filamentphp.com/docs/3.x/tables/grouping#customizing-the-eloquent-query-grouping-behaviour
Kidereo
Kidereo11mo ago
Thanks, Tuto - you certainly sent me in the right direction which is to read the documentation! In the end I used Group::make('post.sort_order') and then ->getTitleFromRecordUsing(fn (Comment $record): string => ucfirst($record->post->title)) to achieve the required effect. Thanks again!
Want results from more Discord servers?
Add your server