ui-sortable icon indicating copy to clipboard operation
ui-sortable copied to clipboard

Swapping elements instead of sorting

Open MadJlzz opened this issue 9 years ago • 2 comments

Hello,

I've been working for a while on this case and it has just been giving me hardcore headaches so here is what I just founded.

I've got some objects in my list (looking like this) :

image

Here is the content binded with ng-model :

image

The thing is that when I am trying to swap the card 2 with the card 0, the result I see is not what I am expecting :

image

In fact, we'll see that card 2 is nicely ordered but we see that card 0 is taking the place of card 1 in the list instead of picking old's card 2 place (at the end).

So here's my question : is that the normal behaviour or is it a real ordering problem ?

Sorry for my poor English, I hope i was clear.

EDIT : After doing some more research and checking in codepens, I think it's the right behaviour. Is it possible to add an option to swap items in the sortableOption instead of reordering them ?

MadJlzz avatar Apr 08 '16 08:04 MadJlzz

This is the expected behavior, regardless from the orientation of the list. The primary use case of jquery-ui-sortable (and as a result, this wrapper library as well) is to move one element before an other one (not swapping) and move all the respective in between elements. In your example specifically, card 2 was moved before card 0 and as a result cards 0 and 1 were pushed to the respective next position. You can probably achieve the swapping use car you described by adding some code in the stop callback and using the properties available on the ui.item.sortable object (where ui is the second parameter of the callback). Take a look at readme.md and api.md .

Thodoris Greasidis Computer, Networking & Communications Engineer

thgreasi avatar Apr 08 '16 08:04 thgreasi

Just saw your edit. I would prefer not to add features the extend the functionality that jquery-ui-sortable offers, so that this library can be both lightweight, not interfere with the jquery-ui lib and also offer the same degree of extensibility/customization. For such use cases I prefer just adding a codepen example in README.md (PRs

please).

Thodoris Greasidis Computer, Networking & Communications Engineer

thgreasi avatar Apr 08 '16 08:04 thgreasi