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);
}
Solution:Jump to 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...
9 Replies
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
thank you defaultSort worked
@Hugh Messenger can you help me with replacing minute to "min" and removing "ago" in this column. i'm using ->since()
Show your column definition.
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.
i see. got it i will customize using formatStateUsing and use diffForHumans() inside it.
thanks for your help
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.
i will check