-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Now allowing defaultSort()'s argument to be a Closure. #9457
Conversation
@awcodes FYI.... There were at least two ways to do this, depending on when/where I have mixed feelings, as there may be advantages to having |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain why you need to pass a function in?
@@ -24,6 +24,8 @@ public function defaultSort(string | Closure | null $column, string | Closure | | |||
$this->defaultSortColumn = $column; | |||
} | |||
|
|||
$direction = $this->evaluate($direction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Evaluation should always happen in getters, it should not be evaluated here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ive changed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Evaluation should always happen in getters, it should not be evaluated here.
I had done that first, as you may have seen. I noticed that this was normally in the getters. But, I changed my mind thinking you might prefer to keep the changes smaller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ive changed it
Thx. You did what I had done on my first iteration. Makes me feel good that I had the right solution...before I changed it. 😅
Sure. I have a filter that filters from today forward or from today backward, depending. I wasn't able to find a way to sort in the filter. The If there's a better way, I'd love to know about it. In any case, this was a bug worth fixing, I thought. 🤓 |
The
Filament\Tables\Table\Concerns\CanSortRecords
trait'sdefaultSort()
method has the following signature:The
$direction
argument, if notnull
, is passed throughStr::lower()
and then assigned to$this->defaultSortDirection
, which is a nullable string.There is at least one problem: if a Closure is passed, then
Str::lower()
chokes on it.I decided to do the following:
$direction
throughevaluate()
right away and allow the rest of the code/types to remain as they are currentlyevaluate()
ingetDefaultSortDirection()
All existing tests pass. No new tests were added.