I've been wrecking my brain on this problem for quite some time now. What I want to achieve is to have two connected drag and drop lists with constant length. Meaning that if I move an element from one list to another, an item gets pushed to the other list. This is of course trivial to achieve during the cdkDropListDropped
event, but I want it to happen as soon as the item is dragged over the list.
Most of my attempts have involved using the cdkDropListEntered
event to either:
- Attempt to simply move the item in the data array:
public enter(list: number, event: CdkDragEnter<User[]>) {
if (list === 0) {
let data = this.schedule.responsible.pop();
this.schedule.queue.unshift(data);
} else {
let data = this.schedule.queue.shift();
this.schedule.responsible.push(data);
}
}
This resulted in errors of the type:
core.js:6185 ERROR DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node
Tried use the
CdkDropList
addItem()
,removeItem()
,getSortedItems()
. This lead to similar problems.Tried to move the DOM-elements themselves with Renderer2 (and leaving data untouched)
Is there any way to achieve what I want?
This magnificent paint drawing helps explain what I want to achieve.