angularjs-dragula icon indicating copy to clipboard operation
angularjs-dragula copied to clipboard

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

Open debslord opened this issue 8 years ago • 2 comments

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

debslord avatar Nov 08 '16 14:11 debslord

@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.

ageiser26 avatar Dec 08 '16 17:12 ageiser26

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

joster-dev avatar Jan 10 '18 23:01 joster-dev