I am trying to do simple drag and drop calculation.
user can drag UP and allowed to drop on BH / OT. But issue is couldn't find the ID where user drop, not working onDrop() func.
Suppose if UP(10) value draged and drop on BH(2), desire updated UP and BH value would be 0 and 12 respectively.
StackBlitz link
Tried Code:
<table
class="hoverable child-table"
style="background-color: white; border-radius: 8px; width: 100%;"
>
<tr
cdkDropList
cdkDropListSortingDisabled
cdkDropListLockAxis="x"
cdkDropListOrientation="horizontal"
(cdkDropListSorted)="f($event)"
class="container"
>
<th style="background-color: rgb(244, 243, 243); max-width: 5%;">MON</th>
<td
style="font-family: 'belgrano', sans-serif; max-width: 5%; border-right: 1px solid black;"
>
NULL
</td>
<td
id="BH"
style="font-family: 'belgrano', sans-serif; max-width: 5%; border-left: 1px solid black;"
(cdkDropListDropped)="onDrop('BH', $event)"
>
{{ BH }}
</td>
<td
id="OT"
style="font-family: 'belgrano', sans-serif; max-width: 5%;"
(cdkDropListDropped)="onDrop('OT', $event)"
>
{{ OT }}
</td>
<td
id="UP"
class="draggable"
style="font-family: 'belgrano', sans-serif; max-width: 5%; border-left: 1px solid black;"
>
<span
cdkDrag
ocColumnDrag
(cdkDragMoved)="dragMoved('UP', $event)"
[cdkDragData]="employee.attendance?.[dateFormt(date)]['UP']"
class="column"
>
{{ UP }}
</span>
</td>
</tr>
</table>
TS:
BH: number = 2;
OT: number = 3;
UP: number = 10;
draggedTdId: string = '';
draggedTdValue: any = '';
dragMoved(tdId: string, e: CdkDragMove) {
this.draggedTdId = tdId;
this.draggedTdValue = e.source.data;
console.log('1', tdId, e.source.data);
}
onDrop(tdId: string, event: any) {
console.log('2', tdId, event);
const draggedTdId = event.item.element.nativeElement.id;
const draggedTdValue = event.item.data;
const droppedTdId = tdId;
console.log('Dragged TD:', draggedTdId, 'Value:', draggedTdValue);
console.log('Dropped TD:', droppedTdId);
}
f(e: any) {
console.log('sorted', e);
}