reppners / ngx-drag-drop

Angular directives using the native HTML Drag And Drop API
https://reppners.github.io/ngx-drag-drop/
BSD 3-Clause "New" or "Revised" License
299 stars 118 forks source link

Inconsistent index when reordering sorted list #87

Open kliszaq opened 4 years ago

kliszaq commented 4 years ago

Hi guys, nice work, I appreciate what you do for the community.

Describe the bug The index returned as a parameter on the onDrop function is different when you move the item from bottom to top and when you move from top to bottom.

To Reproduce Please reuse https://stackblitz.com/edit/ngx-drag-drop-issue-template-tm-awrzjs and set console log or alert on the lines 149:

   onDropLeft(event: DndDropEvent, list?: any[]) {        
        if (list && (event.dropEffect === "copy" || event.dropEffect === "move")) {            
            let index = event.index;

alert(index);

            if (typeof index === "undefined") {
                index = list.length;
            }            
            list.splice(index, 0, event.data);            
        }
    }

Steps to reproduce the behavior:

  1. Drag the Item3 between Item1 and Item2
  2. Output shows index 1. Cool!
  3. Drag the Item1 between Item3 and Item2.
  4. Index is 2.

Expected behavior I would expect here the target index where we would like to insert the new value.

Screenshots

Desktop (please complete the following information):

matheo commented 4 years ago

I found that the library just returns the index of the children inside the dropzone, so it worked for my case where I had a single list of photos: https://github.com/reppners/ngx-drag-drop/issues/79#issuecomment-629739969

zaidas1m commented 9 months ago

Hi kliszaq, where you able to find anything in the plugin that controls this? Probably, we have to fix ourselves the index according to the direction movement until they fix it