Skip to content

Commit 11aee7c

Browse files
MKirovaMKirova
authored andcommitted
Add handling for drop on the whole area. In that case append the new dimension at the end.
1 parent b6487d1 commit 11aee7c

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
(pointerdown)="$event.preventDefault()">
1515

1616
<!-- Columns area -->
17-
<igx-chips-area #colArea>
17+
<igx-chips-area #colArea
18+
(dropped)="onDimDrop($event, colArea, 1)"
19+
igxDrop
20+
(igxDragEnter)="onAreaDragEnter($event, colArea)"
21+
(igxDragLeave)="onAreaDragLeave($event, colArea)"
22+
>
1823
<igx-chip *ngFor="let col of grid.columnDimensions" [draggable]="'true'" [id]="col.fieldName"
1924
[removable]="true" (remove)="columnRemoved($event)"
2025
(dragEnter)="onDimDragEnter($event)"
@@ -46,7 +51,12 @@
4651
<div #pivotContainer class="igx-grid__tr-action" [style.min-width.px] = "grid.pivotRowWidths"
4752
(pointerdown)="$event.preventDefault()" style='display: flex; align-items: flex-end;'>
4853
<!-- Row area -->
49-
<igx-chips-area #rowArea>
54+
<igx-chips-area #rowArea
55+
(dropped)="onDimDrop($event, rowArea, 0)"
56+
igxDrop
57+
(igxDragEnter)="onAreaDragEnter($event, rowArea)"
58+
(igxDragLeave)="onAreaDragLeave($event, rowArea)"
59+
>
5060
<igx-chip *ngFor="let row of grid.rowDimensions" [draggable]="'true'" [id]="row.fieldName"
5161
[removable]="true" (remove)="rowRemoved($event)"
5262
(dragEnter)="onDimDragEnter($event)"

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,34 +67,55 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
6767
event.owner.nativeElement.style.borderLeft = '';
6868
}
6969

70+
public onAreaDragEnter(event, area) {
71+
const dragId = event.detail.owner.element.nativeElement.parentElement.id;
72+
const isValue = this.grid.pivotConfiguration.values.find(x => x.member === dragId);
73+
if (isValue) {
74+
// cannot drag value in dimensions
75+
return;
76+
}
77+
const lastElem = area.chipsList.last.nativeElement;
78+
const targetElem = event.detail.originalEvent.target;
79+
const targetOwner = event.detail.owner.element.nativeElement.parentElement;
80+
if (targetOwner !== lastElem && targetElem.getBoundingClientRect().x >= lastElem.getBoundingClientRect().x) {
81+
area.chipsList.last.nativeElement.style.borderRight = '1px solid red';
82+
}
83+
}
84+
public onAreaDragLeave(event, area) {
85+
area.chipsList.toArray().forEach(element => {
86+
element.nativeElement.style.borderRight = '';
87+
});
88+
}
89+
7090
public onDimDrop(event, area, dimension: PivotDimensionType) {
91+
const dragId = event.dragChip?.id || event.dragData?.chip.id;
7192
const currentDim = dimension === PivotDimensionType.Row ? this.grid.pivotConfiguration.rows :
7293
this.grid.pivotConfiguration.columns;
7394
const chipsArray = area.chipsList.toArray();
74-
const chip = chipsArray.find(x => x.id === event.dragChip.id);
95+
const chip = chipsArray.find(x => x.id === dragId);
7596
const isNewChip = chip === undefined;
76-
const currIndex = area.chipsList.toArray().indexOf(event.owner);
97+
const chipIndex = chipsArray.indexOf(event.owner) !== -1 ? chipsArray.indexOf(event.owner) : chipsArray.length;
7798
if (isNewChip) {
7899
// chip moved from external collection
79100
const oppositeDim = dimension === PivotDimensionType.Row ? this.grid.pivotConfiguration.columns :
80101
this.grid.pivotConfiguration.rows;
81-
const dim = oppositeDim.find(x => x.fieldName === event.dragChip.id);
82-
if(!dim) {
102+
const dim = oppositeDim.find(x => x.fieldName === dragId);
103+
if (!dim) {
83104
// you have dragged something that is not a dimension
84105
return;
85106
}
86107
dim.enabled = false;
87108

88109
const newDim = Object.assign({}, dim);
89110
newDim.enabled = true;
90-
currentDim.splice(currIndex, 0, newDim);
111+
currentDim.splice(chipIndex, 0, newDim);
91112
this.grid.setupColumns();
92113
} else {
93114
// chip from same collection, reordered.
94-
const newDim = currentDim.find(x => x.fieldName === event.dragChip.id);
95-
const dragChipIndex = chipsArray.indexOf(event.dragChip);
115+
const newDim = currentDim.find(x => x.fieldName === dragId);
116+
const dragChipIndex = chipsArray.indexOf(event.dragChip || event.dragData.chip);
96117
currentDim.splice(dragChipIndex, 1);
97-
currentDim.splice(currIndex, 0, newDim);
118+
currentDim.splice(dragChipIndex > chipIndex ? chipIndex : chipIndex - 1, 0, newDim);
98119
}
99120
this.grid.pipeTrigger++;
100121
}

0 commit comments

Comments
 (0)