hentiru
Numeric TextColumn: sortable() not working properly
Hi, I've faced this issue: sortable() method change randomly the order of the column with numeric field. It doesn't even give an "alphabetical" order on numbers. it was simply random (or in any case not a recognizable order, I couldn't find a pattern...)
I found a solution passing sortable as in the code below, but I wonder if it's a known behavior and it's what you guys thought, maybe someone has some insights?
return TextColumn::make('priority')
->label('')
->html()
->state('●')
->sortable(query: function(Builder $query, string $direction): Builder {
$query->getQuery()->orders = [];
$query->orderBy('priority', $direction);
return $query;
})
->size(TextColumnSize::Large)
->color(fn (Order $record): string => match (self::determinePriority($record->priority)) {
'high' => 'danger',
'medium' => 'warning',
'low' => 'info',
default => 'gray',
});
FYI: I tried adding numeric(), removing html(), removing state() showing the numbers to try understanding the pattern and it didn't work...
15 replies