Default grouping direction

Is there any way we can set up the default grouping direction so that it is desc instead of asc ? I think right now it is not really possible given the below line, where the asc is hard-coded: https://github.com/filamentphp/filament/blob/c634245cd64af3dc06bd0d7ba40d5d2b76b96b38/packages/tables/resources/views/components/groups.blade.php#L28
10 Replies
pechtelt
pechtelt16mo ago
You can set an default sort on the table? Or is that not what you mean?
uzdacpdz (Doug Dimmadome)
For sorting all records in the table yes, but in case I group my records (by date for example), I want the groups to be sorted with the latest dates first and for now weirdly enough that doesn't seem to be possible :/
toeknee
toeknee16mo ago
you can use the getTableQuery and write a custom ordering
Fogzy
Fogzy15mo ago
did you figure this out? i'm trying to group by order_number but sort by order_date. this works when the order_date is the same, but when changed, it creates separate groups
uzdacpdz (Doug Dimmadome)
Nope, ended up just dropping it as it wasn't a critical feature for me :/
chadonsom
chadonsom13mo ago
Hey just putting in a note that I was looking for this feature as well
tee
tee12mo ago
Yes it would be great to have this feature
Majid Al Zariey
Majid Al Zariey11mo ago
I had to do it like this for now
$table->groups([Group::make('date')
->orderQueryUsing(fn($query,)=>
$query->orderBy("date","desc"))])
->groupingSettingsHidden()
->defaultGroup('date')
$table->groups([Group::make('date')
->orderQueryUsing(fn($query,)=>
$query->orderBy("date","desc"))])
->groupingSettingsHidden()
->defaultGroup('date')
Tieme
Tieme11mo ago
@uzdacpdz (Doug Dimmadome) You can already define default order. Below is my "Group" with orderQueryUsing
public static function table(Table $table): Table
{
return $table
->columns([

])
->defaultGroup('date')
->groups([
Tables\Grouping\Group::make('date')
->collapsible(true)
->date(true)
->orderQueryUsing(fn (Builder $query, string $direction) => $query->orderBy('date', 'desc')->orderBy('id', 'desc')),
])
->groupingSettingsHidden()
->configure([
Table::$defaultDateDisplayFormat = 'l d F Y',
])
->defaultSort('date', 'desc');
}
public static function table(Table $table): Table
{
return $table
->columns([

])
->defaultGroup('date')
->groups([
Tables\Grouping\Group::make('date')
->collapsible(true)
->date(true)
->orderQueryUsing(fn (Builder $query, string $direction) => $query->orderBy('date', 'desc')->orderBy('id', 'desc')),
])
->groupingSettingsHidden()
->configure([
Table::$defaultDateDisplayFormat = 'l d F Y',
])
->defaultSort('date', 'desc');
}
tomtom
tomtom8mo ago
Hi, has anyone found how to do this? The solution given above hide the dropdown for all groups so that is not an option for me. I ended up hard coding the direction in the ->orderQueryUsing(fn (Builder $query, string $direction) => $query->orderBy('date', 'desc')) but the 'direction' dropdown no longer works.
Want results from more Discord servers?
Add your server