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
cheesegrits9mo 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
Roberto9mo ago
thank you defaultSort worked
Roberto
Roberto9mo 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
cheesegrits9mo ago
Show your column definition.
Roberto
Roberto9mo ago
No description
cheesegrits
cheesegrits9mo 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
Roberto9mo ago
i see. got it i will customize using formatStateUsing and use diffForHumans() inside it. thanks for your help
cheesegrits
cheesegrits9mo 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
Roberto9mo ago
i will check