Default sort direction for a column - descending first

To improve the UX I wanted to change how the ‘Updated at’ timestamp are sorted descending on first click of a column. I know you can change the default order for the whole table but here I'm referring to the individual column sorting - when you click on a column. On first click of a timestamp column you most likely want to see the recent first, and not oldest. If I reverse the direction in the query it kinda works but the label/arrow are incorrect.
Tables\Columns\TextColumn::make('updated_at')
->sortable(query: fn (Builder $query, string $direction): Builder =>
$query->orderBy('updated_at', $direction === 'asc' ? 'desc' : 'asc'))
Tables\Columns\TextColumn::make('updated_at')
->sortable(query: fn (Builder $query, string $direction): Builder =>
$query->orderBy('updated_at', $direction === 'asc' ? 'desc' : 'asc'))
1 Reply
Dan Harrin
Dan Harrin15mo ago
We don't have a way to customize which sort comes first yet, but I would accept a PR to add an API that can do that