SortableJS / Sortable

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
https://sortablejs.github.io/Sortable/
MIT License
29.59k stars 3.7k forks source link

How to disable dragging in the middle of another list? #2050

Open rafalxyz opened 3 years ago

rafalxyz commented 3 years ago

I have two lists (A, B) with disabled sorting. When I drag element from list A to list B, I'd like the dragged element to be pushed on top of list B even if mouse cursor is not on top of list B. Something like this: https://sortablejs.github.io/Sortable/#sorting-disabled but without the possibility to insert elements in the middle of the list on the right side.

dzero1 commented 3 years ago

I had a similar problem. How about a workaround using dataIdAttr & sort function?

rafalxyz commented 3 years ago

@dzero1 Thanks for answer. Should I just reorder DOM elements in on move event handler? I get strange behavior if I do that. Dragged element jumps between top and middle of the list when I move cursor.

dzero1 commented 3 years ago

I'm just changing the data-id of my elements. then call sort function of the sortablejs instance. In your case, I think you can use onEnd event. Just update each DOM element data-id and call the sort.