-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Sortable Relations #5298
Sortable Relations #5298
Conversation
@tobias-kuendig while this is certainly an improvement, I would much rather see support for reordering added directly to the Lists widget itself with the ability to drag and drop the rows within the widget rather than kicking the user to a separate screen or popup to handle the ordering. Is that something that you're interested in? |
That would definitely be the nicer solution. It is what the suggestions in #3010 were trying to achieve. Where this always fell apart though, was with larger lists with multiple pages. How would you move a record from page 2 up to page 1? This was my number 1 problem in every sortable list situation. If we find a good solution to this problem I can give the sortable list widget a go. |
@tobias-kuendig One of the options I considered when I had thought about this in March (although this felt like a lifetime ago, thanks COVID) - was to have "hotspots" on the left and right side of the list that would trigger a "previous" or "next" page when you moved your mouse over it while dragging/reordering a list item. I've seen this sort of interaction before - as long as there's some sort of UI hint and the page change is staggered (ie. only does a page change every second), it should cover this case. |
Good thinking, @bennothommo! Two things that come to mind:
I'm just dropping my initial thoughts here. Does anyone know how other CMS are tackling this problem? Edit: Another thing I just noticed, what if I have sorted the table by any other column than the sort order? Is sorting disabled? Do we need a "reorder enabled" mode, where the table is changed to a forced sort order? What If you enable this on page 25 where the record you want to move around is only on while the list is sorted by name? Wouldn't that be infuriating if the row simply disappeared to another page once you toggle the "reorder enabled" mode? |
@tobias-kuendig All very good points, and I dare say this is likely the reason why it hasn't been attempted (and possibly why the reordering occurs on another page with I think if sorted is enabled, then re-ordering by other columns must be disabled, otherwise it makes "inline" sorting pointless and/or confusing to the actual order of items. The "hover" type page switch can always be shorter too, I was merely saying a second off the top of my head - it just needs to be somewhat staggered so that someone doesn't go from page 1 to page 50 in quick succession. As to your other points, I'll have to think about those. |
My dua lipa/2¢: reordering is isolated (on another controller action) from listing because of sort/search/filter list complications, so it is best to do it as initially proposed in this issue (popup). |
I think the sort in table is the best solution. Maybe you can check if the results are paginated. If so, show a button to sort like seen in the popup. If there are less than the per page, then use the sort order in table. Most of the related lists I'm using only have like 10 records or so |
This is a pretty good article on the subject of manually sorting large data sets: https://www.bennadel.com/blog/2532-the-user-experience-ux-of-manually-sorting-data.htm |
E-commerce product listings inside a category? I know at least one shopkeeper that loves to re-sort her stuff regularly... |
This is a valid point. Are you suggesting that we might disable sortable table headers if a relation manager is marked as
Absolutely, the popup solution is cumbersome to use in that scenario as well, but it is still better than any table solutions (especially when you factor in different sorting options for the table and search filters)
In my experience, people really love to sort things. All the things! But it's true, most relation widgets don't have more than a few entries. The shop category example is the one that comes to mind. We have solved this problem in our Mall plugin by re-using the ReorderController. This form would benefit from the popup solution. Edit: Users usually don't want to sort all products in a category. What they want is to have their top selling products on the first page, or their favourite products displayed in the first row. So most of the time, a Maybe the best solution is a hybrid one as suggested by @SebastiaanKloos. Sortable rows in the table as long as there is no active pagination. Then offer the popup option if pagination is enabled. I can invest some more time in this PR and try to implement a solution, if it is a possible way to go. |
Thirty-something usually. |
This took some more effort than expected but I think I've got a nice solution now: The The A couple of notes:
I have updated my fork of the test plugin with a working implementation: octobercms/test-plugin@master...OFFLINE-GmbH:sortable-relations
If this PR gets accepted I will provide documentation for the new features. |
modules/backend/behaviors/relationcontroller/partials/_button_reorder.htm
Show resolved
Hide resolved
In theory yes, we would only need to send additional Replicating this using the existing |
It depends. The included sortable plugin is very lean and has a limited feature set. Also, the SortableJS would certainly optimize the standard sort actions as it covers lots of edge-cases and has support for animations. I don't think, however, it makes sorting a nested tree inside a |
Nice work @tobias-kuendig 🎉 . Lots to review here! Will get to this one soon As a side note, switching to SortableJS was something we looked at but it didn't offer an on par feature set. So is likely a better path to just improve the existing sortable library as we've done so in the past. It's not just a case of "newer" = "better" |
Hey guys, It's almost Hacktoberfest again :) Any updates on this? Maybe we can extend this in a plugin? |
@robinbonnes yep this will be good addition and if allows sorting rows in table that will be best feature! |
@robinbonnes This feature is being implemented in stages. The initial support has been added to lists in v2.1. That is the hardest part completed. We hope to have sortable relations included in v2.2 for belongsToMany and hasMany relationship types. |
This has been reviewed today and we can confirm sortable relations will be included as part of the v2.2 release. Thank you for your work on this @tobias-kuendig! 🙏 Documentation can be found here: https://docs.octobercms.com/3.x/extend/lists/structures.html#sorting-related-records |
It is Hacktoberfest once again, so what better time to propose some new features for my favourite CMS! 🤗
The wish for sortable relations has been around for some years (#3010). The current solutions are rather hacks than solutions and not in line with October's UI. This PR proposes a possible solution to this problem by adding a
ReorderRelationController
:With this PR, the following steps are required to implement a sortable relation:
SortableRelation
trait in your parent model$sortableRelations
propertyReorderRelationController
in your Controllerreorder
toolbar button to your relation widget configThat's it!
I have added an example implementation to the test plugin (Posts -> Edit Post -> Galleries):
OFFLINE-GmbH/test-plugin@f8eb223
You can optionally define a
public $reorderRelationConfig = 'config_reorder_relation.yaml';
property on your controller to define where the name attributes for the treelist control should be taken from:If nothing is configured, the control defaults to the
name
thentitle
attributes.Let me know what you think!
Resolves #3010