bevacqua / angularjs-dragula

:ok_hand: Drag and drop so simple it hurts
https://bevacqua.github.io/angularjs-dragula
MIT License
509 stars 110 forks source link

When using a filtered ng-repeat the DOM element index differs from model index #98

Open debslord opened 7 years ago

debslord commented 7 years ago

Currently you cannot drag items while the list is filtered. dragula becomes confused with the array index. In this plunker example you can try to search for "t" and then drag and drop "them" within the list. You will notice, that the hidden "Explore" will be moved instead.

http://plnkr.co/edit/bKNeo9cyKyjY3GpJcIhY?p=preview

Plnkr taken from here: https://github.com/bevacqua/angular-dragula/issues/29 Also highlighted that would be issue with this pull request: https://github.com/bevacqua/angular-dragula/pull/9

ageiser26 commented 7 years ago

@debslord I'm not sure if it'll help you or not but, my team had the same problem today.

I edited service.js line #50 to include the following -

if (dropElm.hasAttribute('ng-repeat')) { dropElmModel = angular.element(dropElm).scope()[dropElm.getAttribute('ng-repeat').split(' ')[0]]; dragIndex = sourceModel.indexOf(dropElmModel); }

This finds the index of the model in unfiltered source. It's barbaric and but, it gets the job done.

joster-dev commented 6 years ago

+1 not using filter exactly but it does not work when using pipes that alter the positioning of items on screen