ember-cli-sortable
ember-cli-sortable copied to clipboard
calling onItemMoveAction with the re-ordered collection would be nice
I have a situation where I want to make a list of images sortable. The collection of images is using sortBy
to maintain order using a position property. This gets stored on the backend, and I need to update the server with a contiguous sequence of positions every time you re-order the list.
Getting the old and new indices in the onItemMoveAction isn't very helpful, because it only lets me update that position property on the single item dropped. Since I'm using a sorted collection, every time I use this.get('images')
they get re-sorted according to their position
.
Passing the collection
in as an argument to the action solves this problem, because then I have the newly ordered collection of images. I can update the position
property on all of them, and then make my request to the server to persist the ordering.
Would you accept a PR for this?
We currently have it setup with two way data-binding. So the collection you want is the one that you're giving the addon to play with, you should have access to it.
I will be refactoring this plugin to use data-down and actions-up methodology, soon. That should solve your problem.
The collection that I provided it via
sortable-items [
itemCollection=images
handle="li"
draggable="li"
templateName="images/image"
class="list"
onItemMoveAction="reOrderImages" ]
is unfortunately a sorted collection, so after Sortable mutates it, it re-sorts when I access it via this.get('images')
.
@MaazAli any word on the refactor? We're still using a patched version of this package in production