For defaultSort() which accepts a string, is there an easy way to sort by multiple columns?

->defaultSort("title") // group.group, sort_order
4 Replies
Patrick Boivin
Patrick Boivinβ€’16mo ago
I'm not sure there's an easy solution for this... you can probably override the applyDefaultSortingToTableQuery() method on your Page or custom component. Easy enough I guess πŸ˜„
FullyLoadedTech
FullyLoadedTechOPβ€’16mo ago
Do you have an example how to use that? I couldn't find that method defined anywhere. I'll keep looking.
Patrick Boivin
Patrick Boivinβ€’16mo ago
Something like this on your page class:
protected function applyDefaultSortingToTableQuery(Builder $query, string $sortColumn, string $sortDirection): Builder
{
return $query
->orderBy('category', 'ASC')
->orderBy('title', 'ASC');
}
protected function applyDefaultSortingToTableQuery(Builder $query, string $sortColumn, string $sortDirection): Builder
{
return $query
->orderBy('category', 'ASC')
->orderBy('title', 'ASC');
}
I don't know if it's going to work everywhere, but something to experiment πŸ˜„
Martin Branches
Martin Branchesβ€’11mo ago
This is not working for me (filament 3) Method 'App\Filament\Resources\MyCountryResource\Pages\ListMyCountries::applyDefaultSortingToTableQuery()' is not compatible with method 'Filament\Resources\Pages\ListRecords::applyDefaultSortingToTableQuery()'.intelephense(P1038) any other ideas?
Want results from more Discord servers?
Add your server