akserg / ng2-dnd

Angular 2 Drag-and-Drop without dependencies
MIT License
838 stars 251 forks source link

Drop is dropping into multiple targets #273

Closed ranjith88 closed 6 years ago

ranjith88 commented 6 years ago

I have Single source and multiple targets.

For Eg: I have a source with 5 rows. This is in a table.

On the Target side we have 3 tables. Now Drag and Drop is working but it is dropping the data into all the three targets. How do I distinguish the targets. I am not talking about restrictions. But when i drag into table 1 on the target it is getting dropped to all the 3 tables on the target side and same time I want it to delete from the Source side.

Need the dragged row to be moved only to the dragged one.

Code:

Document Type Year
{{px.DocType}} {{px.Year}}
    <div class="col-lg-9">
        <div>
            <div class="border border-dark" dnd-droppable (onDropSuccess)="addTo($event)">
                <table class="table table-bordered mb-2">
                    <thead class="thead-light">
                        <tr>
                            <th scope="col">Document XYZ</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr *ngFor="let target of targetList">
                            <td>{{target.DocType}}</td>
                            <td>{{target.TaxYear}}</td>
                        </tr>
                    </tbody>
                </table>
                </div>
            <div>
                <table class="table table-bordered mb-2">
                    <thead class="thead-light">
                        <tr>
                            <th scope="col">Document XYZ</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr *ngFor="let target of targetList">
                            <td dnd-draggable sortable="true" [dragData]="target">{{target.DocType}}</td>
                            <td dnd-draggable sortable="true" [dragData]="target">{{target.Year}}</td>
                        </tr>
                    </tbody>
                </table>
                <table class="table table-bordered mb-2">
                    <thead class="thead-light">
                        <tr>
                            <th scope="col">Document XYZ</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr *ngFor="let target of targetList">
                            <td dnd-draggable sortable="true" [dragData]="target">{{target.DocType}}</td>
                            <td dnd-draggable sortable="true" [dragData]="target">{{target.Year}}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

on Coponent.ts

targetList: DocumentType[] = []; addTo($event: any) { this.targetList.push($event.dragData); }