I'm aware of the baked-in Sortable trait, and have used it extensively with "top-level" models as well as nested sets.
However, I'd like to be able to extend this behavior to child items. For example in a many-to-many relationship between Products and Categories. My solution for now is to have the relation manager pop up a form to edit the sort_order (stored as pivot data in the "category has product" link table) manually for the Products in a Category, which works, but is a bit clunky and could mean a lot of editing of records if you want to insert a new item.
Does anyone know of any examples of drag-and-drop reordering either directly in the relation manager, or through some other solution? Any other ideas on how to make this a little more user-friendly?
Thanks for the reply Crazymodder! You set me on the right path for sure. I managed to get this working for Relation lists, though it did require a bit of fiddling. If anyone is going to try this I'd recommend trying out the draganddrop plugin on a non-relation list first to get familiar with it.
Here's the steps I took, using my setup of a Product hasMany Variants
1) Add the hidden input as per usual with the draganddrop plugin (see the example model in the plugin) -- this just adds the object id to each row of the list so that it can be accessed via javascript when the "Reorder" button is clicked.
The last 4 lines of code are needed to re-initalize the relation in the context of the controller before the updated list can be returned to the browser. See discussion about this behaviour here: https://octobercms.com/forum/post/problem-with-relationrefresh
Thanks for the reply Crazymodder! You set me on the right path for sure. I managed to get this working for Relation lists, though it did require a bit of fiddling. If anyone is going to try this I'd recommend trying out the draganddrop plugin on a non-relation list first to get familiar with it.
Here's the steps I took, using my setup of a Product hasMany Variants
1) Add the hidden input as per usual with the draganddrop plugin (see the example model in the plugin) -- this just adds the object id to each row of the list so that it can be accessed via javascript when the "Reorder" button is clicked.
The last 4 lines of code are needed to re-initalize the relation in the context of the controller before the updated list can be returned to the browser. See discussion about this behaviour here: https://octobercms.com/forum/post/problem-with-relationrefresh
Thanks for the reply Crazymodder! You set me on the right path for sure. I managed to get this working for Relation lists, though it did require a bit of fiddling. If anyone is going to try this I'd recommend trying out the draganddrop plugin on a non-relation list first to get familiar with it.
Here's the steps I took, using my setup of a Product hasMany Variants
1) Add the hidden input as per usual with the draganddrop plugin (see the example model in the plugin) -- this just adds the object id to each row of the list so that it can be accessed via javascript when the "Reorder" button is clicked.
The last 4 lines of code are needed to re-initalize the relation in the context of the controller before the updated list can be returned to the browser. See discussion about this behaviour here: https://octobercms.com/forum/post/problem-with-relationrefresh
Thanks for the reply Crazymodder! You set me on the right path for sure. I managed to get this working for Relation lists, though it did require a bit of fiddling. If anyone is going to try this I'd recommend trying out the draganddrop plugin on a non-relation list first to get familiar with it.
Here's the steps I took, using my setup of a Product hasMany Variants
1) Add the hidden input as per usual with the draganddrop plugin (see the example model in the plugin) -- this just adds the object id to each row of the list so that it can be accessed via javascript when the "Reorder" button is clicked.
The last 4 lines of code are needed to re-initalize the relation in the context of the controller before the updated list can be returned to the browser. See discussion about this behaviour here: https://octobercms.com/forum/post/problem-with-relationrefresh