Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Swapping elements instead of sorting #449

Open
MadJlzz opened this issue Apr 8, 2016 · 2 comments
Open

Swapping elements instead of sorting #449

MadJlzz opened this issue Apr 8, 2016 · 2 comments

Comments

@MadJlzz
Copy link

MadJlzz commented Apr 8, 2016

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 ?

@thgreasi
Copy link
Contributor

thgreasi commented Apr 8, 2016

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
Copy link
Contributor

thgreasi commented Apr 8, 2016

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 thgreasi changed the title Suspecting that the sorting list is malformed Swapping elements instead of sorting Apr 8, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants