akserg / ng2-dnd

Angular 2 Drag-and-Drop without dependencies
MIT License
839 stars 252 forks source link

Get the index of where something was dropped #213

Open mcblum opened 6 years ago

mcblum commented 6 years ago

Thank you for this awesome library!

mcblum commented 6 years ago

Just a quick followup to this - I did get the multi-list sortable thing working, but the issue is now that items in the source list should not be reorderable and a copy should be made when items are dragged from the source to the target. If anyone has any ideas, please let me know!

Here's the target list:

                <div class="schema-list"
                     dnd-droppable
                     [dropZones]="['schema']"
                     (onDropSuccess)="addElement($event)">
                    <div class="schema-element-sortable-wrapper" dnd-sortable-container [sortableData]="schema">
                        <app-object-card label="{{element.label}}"
                                         *ngFor="let element of schema;let i = index;"
                                         dnd-sortable
                                         [sortableIndex]="i"
                                         icon="{{element.icon}}">
                            <div class="body">
                                {{element.description}}
                            </div>
                        </app-object-card>
                    </div>
                </div>
            </div>

This is working, it's just that the elements are not sortable until they are added to the list.

2advancesolutions commented 5 years ago

Here how i got the item of the drop array const dropElement = $event.mouseEvent.path[0]; const dropItem = dropElement.innerText; dropList.indexOf(dropItem)to find the dropIndex

I got the $event from (onDropSuccess)="transferDataSuccess($event)" method