nova-attach-many icon indicating copy to clipboard operation
nova-attach-many copied to clipboard

Added 'orderBy' option

Open YasamDevelopment opened this issue 3 years ago • 2 comments

Hi Brian,

I'm pretty new when it comes to creating pull requests, and I don't thoroughly understand your (and Nova's) codebase, but I hope this Pull Request will at least give you a good idea of a way to implement an "orderBy" option with which the user can specify the columns by which to order the listing by.

Just as an example as to how this would look in a Resource, which uses your AttachMany field:

AttachMany::make('People')
    ->showRefresh()
    ->orderBy(['last_name', 'first_name']),

Please let me know if there's anything else I can do from my end.

Thank you for your very useful & helpful tool!

YasamDevelopment avatar May 04 '21 19:05 YasamDevelopment

Hi @dillingham,

I added another commit to this pull request - to allow for user to specify "ASC" or "DESC" sort direction. So now the user could specify the AttachMany field like so:

AttachMany::make('People')
    ->showRefresh()
    ->orderBy(['last_name => 'ASC', 'first_name', 'age' => 'desc']),
  • 'asc' or 'desc' is case-insensitive
  • If any elements in the 'orderBy' array don't specify 'asc' or 'desc', ascending is assumed.

Please let me know if you have any other questions, or if there's anything else I could do.

Thanks again.

YasamDevelopment avatar May 05 '21 09:05 YasamDevelopment

https://github.com/dillingham/nova-attach-many/issues/24#issuecomment-839254550 posted by @davejamesmiller shows how "sorting" can quite easily be done without the need for this Pull Request or changing any code in this repository. This Pull Request can be closed.

briggsm avatar May 12 '21 18:05 briggsm