-
Notifications
You must be signed in to change notification settings - Fork 34
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
[Feature request] Sort relation fields by column (BelongsTo, HasMany etc.) #1241
Comments
Hello, have this functionality been implemented yet? Thanks |
@didix16 As far as I can tell this hasn't been implemented as of version 3.0.2. I'd really like this feature, too. |
Oh, ok. Thanks @larshanskrause . We will keep waiting then. |
Is there any update on this from Nova? |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi there!
Currently there is no control over how the related fields are sorted when displayed in the select dropdown lists.
My proposal is to expose a sortBy method on all relation fields and then also update the AssociatableController::index() that prepares the resources listing.
Like so:
So in the AssociatableController::index() method instead of getting resources like
See we have a hardcoded
->sortBy('display')->values()
as default ordering, what if we want to display latest updated records first?A better approach is to perform the ordering based on column and direction (taken from above)
so AssociatableController::index() should perform ordering like:
So all changes that need to be done are in the controller index method and probably a shared Sortable trait for the relation fields.
finally we can have a default sortByColumn taken from the related $resource::title
so all relation fields should have or this can be defaulted in the controller (not very clear though)
I think this can be a great addition to the otherwise awesome Laravel Nova.
It will also resolve one of the closed issues
#156 (comment)
Greetings,
Stoyan
The text was updated successfully, but these errors were encountered: