我在一个角度项目上工作,我想要有列,其中的元素可以放在任何列中,同时,我想拖放列本身来改变列的顺序。
Here is moving the elements between the columns From Trello which I already have
And here is the functionality of changing the order of the columns From Trello that I want to implement如果有一种方法可以实现这个功能,那将会很有帮助。
我目前正在使用cdk/drag-drop在列之间移动元素,但我被困在移动列本身上。我浏览了https://material.angular.io/cdk/drag-drop/examples,但找不到在同一个页面中包含多种类型的ckdDrag元素的方法。
发布于 2020-06-14 23:47:40
没有问题,你可以有一个数组,例如
list = [
{ head: "to do", items: ["Get to work", "Pick up groceries", "Go home", "Fall asleep"] },
{ head: "Done", items: ["Get up", "Brush teeth", "Take a shower", "Check e-mail", "Walk dog"] }
];
一个.html
<div cdkDropList (cdkDropListDropped)="dropColumns($event)">
<div cdkDropListGroup>
<div class="example-container" *ngFor="let items of list;let i=index" cdkDrag>
<h2>{{items.head}}</h2>
<div cdkDropList #todoList="cdkDropList" [cdkDropListData]="items.items"
class="example-list" (cdkDropListDropped)="drop($event)">
<div class="example-box" *ngFor="let item of items.items" cdkDrag>{{item}}</div>
</div>
</div>
</div>
</div>
注意,您在<div cdkDropListGroup>
中包含了"columns“
并且这两个函数会丢弃
dropColumns(event: CdkDragDrop<string[]>) {
moveItemInArray(this.list, event.previousIndex, event.currentIndex);
}
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(
event.container.data,
event.previousIndex,
event.currentIndex
);
} else {
transferArrayItem(
event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex
);
}
}
请参见stackblitz (如果您“从标题拖动”,则需要重新排序“列”)
https://stackoverflow.com/questions/62370595
复制相似问题