F
Filament14mo ago
Roberto

Sorting is not working

Hello there, i'm trying to sort date column. field name is "since" So, i did the following in Resource. but it is not showing properly. tried with 'asc' but didn't work protected function getTableQuery(): Builder { return parent::getTableQuery()->orderBy('since', 'desc')->whereStatus(false); }
No description
Solution:
The image you showed appears to be sorted? Have you tried using defaultSort() on a column? https://filamentphp.com/docs/3.x/tables/columns/getting-started#sorting-by-default...
Jump to solution
9 Replies
Solution
cheesegrits
cheesegrits14mo ago
The image you showed appears to be sorted? Have you tried using defaultSort() on a column? https://filamentphp.com/docs/3.x/tables/columns/getting-started#sorting-by-default
Roberto
RobertoOP14mo ago
thank you defaultSort worked
Roberto
RobertoOP14mo ago
@Hugh Messenger can you help me with replacing minute to "min" and removing "ago" in this column. i'm using ->since()
No description
cheesegrits
cheesegrits14mo ago
Show your column definition.
Roberto
RobertoOP14mo ago
No description
cheesegrits
cheesegrits14mo ago
OK, since() just uses Carbon's diffForHumans(), and I don't know of any way to modify the output of that. So you'd probably have to use your own formatStateUsing(function ($state) { ... }) instead iof since(), and create the string yourself. Maybe call diffForHumans() yourself then replace strings as required.
Roberto
RobertoOP14mo ago
i see. got it i will customize using formatStateUsing and use diffForHumans() inside it. thanks for your help
cheesegrits
cheesegrits14mo ago
Yes, use diffForHumans() in your function, not since(), my bad. I'm not sure if $state will be a date string or a Carbon instance. I think it'll be a Carbon instance, assuming you cast that field to datetime in your model, but not 100% sure on that.
Roberto
RobertoOP14mo ago
i will check
Want results from more Discord servers?
Add your server