Last active
March 30, 2021 18:21
-
-
Save krusli/a51ecd07fb84bbc9ae04eea2e37b14dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row" cdkDropListGroup> | |
<!-- NOTE that each item gets its own cdkDropList, then we treat it as a series of different cdkDropLists. --> | |
<div *ngFor="let item of items; index as i" | |
class="col-6 col-md-4 col-lg-3 mb-3" | |
cdkDropList | |
[cdkDropListData]="i" | |
cdkDropListOrientation="horizontal"> | |
<app-item [item]="item" cdkDrag (cdkDragEntered)="entered($event)" (cdkDragEnded)="ended($event)" [cdkDragData]="i"> | |
</app-item> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lastFrom: number; | |
lastTo: number; | |
constructor(private cd: ChangeDetectorRef) { } | |
entered(e: CdkDragEnter) { | |
if (this.items && this.items.length === 1) { | |
return; | |
} | |
this.lastFrom = e.item.data; | |
this.lastTo = e.container.data; | |
} | |
ended(e: CdkDragEnd) { | |
if (this.items && this.items.length === 1) { | |
return; | |
} | |
if (this.lastFrom === undefined || this.lastTo === undefined) { | |
return; | |
} | |
moveItemInArray(this.items, this.lastFrom, this.lastTo); | |
this.cd.detectChanges(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to handle some corner cases.