mfuu / vue-virtual-drag-list

A virtual scrolling list component that can be sorted by dragging
https://mfuu.github.io/vue-virtual-drag-list/
MIT License
32 stars 11 forks source link

Can't drop the item back in the same spot #3

Closed krispern closed 2 years ago

krispern commented 2 years ago

When dragging an item in the list, it's not possible to put it back where it was taken from without putting it somewhere else first.

mfuu commented 2 years ago

@krispern Sorry for the late reply. This problem has been fixed in the latest version

krispern commented 2 years ago

After updating to version 2.4.0, I get the following error message when running my project:

 ERROR  Failed to compile with 1 error                                                                        15:33:25

This dependency was not found:

* js-draggable-list in ./node_modules/vue-virtual-draglist/dist/index.js

To install it, you can run: npm install --save js-draggable-list
Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\DumpStack.log.tmp'

Looks like there's a new package that's not in the build?

mfuu commented 2 years ago

@krispern i made a mistake,please update to 2.4.1 to solve this problem

krispern commented 2 years ago

There seems to be another problem. For reference, I'm using Chrome.

Nothing can be dragged to be the last item in the list. And when trying to drag the last item, there are errors in the Dev Tools' console.

index.js?c52c:223 Uncaught TypeError: Cannot read properties of undefined (reading 'left')
    at Draggable._handleMousedown (index.js?c52c:223:1)
_handleMousedown @ index.js?c52c:223
index.js?c52c:358 Uncaught TypeError: Cannot read properties of undefined (reading 'left')
    at Draggable._animate (index.js?c52c:358:1)
    at HTMLDocument.document.onmousemove (index.js?c52c:268:1)
_animate @ index.js?c52c:358
document.onmousemove @ index.js?c52c:268
index.js?906e:375 Uncaught TypeError: Cannot read properties of undefined (reading 'top')
    at Draggable.dragEnd (index.js?906e:375:1)
    at HTMLDocument.document.onmouseup (index.js?c52c:284:1)

I think it's an index problem, because the item I'm dragging is being put onto the place before the item I'm on.

krispern commented 2 years ago

I think I've figured out the issue. The array returned with @ondragend is not ok. The item being moved is still in the same place in the list and the location moved to has been set to null in the returned array.

UPDATE: It's because we have the draggable="true" on a sub-element. So, when being dragged around in the new version, the sub-element gets removed from its location and added onto the main list, when messes up the indexes and returns the wrong list. Is there any way to specify that I want to move a whole row, but only by a specific sub-element, e.g. one that has the "move" icon on it? It used to work like that in the previous versions

mfuu commented 2 years ago

Can you take a look at your code if I can, I can probably see where the problem is

mfuu commented 2 years ago

@krispern please update to 2.4.2,now you can define the elements you need to drag and drop by yourself,If not set, it will drag a whole row

krispern commented 2 years ago

Works as it used to now. Thank you