For some reason, when sorting items I have 1-based indexes which messes things up when it comes to run items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]);
I've had to set this thus:
oldIndex = evt.oldIndex - 1,
newIndex = evt.newIndex - 1
Once I do that, things run fine. Could this be caused by having an element which is not sortable within the same div?
The same issue for me, 1.7.0v start indexing from 0, 1.8.3v starts indexing from 1.
I was using ^1.7.0 in my package.json so after build 1.8.3v was downloaded, this is how I noticed.
@cmoutafidis This is not true, but the indexing is more lenient to include non-draggable items. You will have to compensate for any elements in the element you passed into Sortable that are not draggable.
@cmoutafidis This is not true, but the indexing is more lenient to include non-draggable items. You will have to compensate for any elements in the element you passed into Sortable that are not draggable.
So, _Sortable will include non-draggable items_ when returning indexes.
Should this be documented somewhere?
@Backoo It is never documented that it only includes draggable items
In my previous comment I wrote about the documentation because the fact Sortable will include non-draggable items can lead to subtle confusion and unexpected results when using Sortable, as happened to me.
BTW Is the draggable option _really_ needed if all the direct children items will be draggable?
@Backoo No, if all the direct children are draggable then the option will include them by default, unless it is a ul or ol then it will only include direct li descendants.
In general, I would try to avoid having non-draggable items in the Sortable element, as I have not tested it so there could be even more unexpected behavior.
@cmoutafidis @Backoo You can now use event.newDraggableIndex to get the index of the element only counting draggable elements.
Most helpful comment
@cmoutafidis @Backoo You can now use
event.newDraggableIndexto get the index of the element only counting draggable elements.