Skip to content

Commit a914242

Browse files
committed
fix(row-drag): fix disappearing rows in row drag samples
1 parent 82c9cbe commit a914242

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/app/grid/grid-drop-indicator/grid-drop-indicator.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class GridDropIndicatorComponent implements AfterViewInit, OnDestroy {
2727
private highlightedRow: HTMLElement;
2828

2929
constructor() {
30-
this.data = DATA;
30+
this.data = [...DATA];
3131
}
3232

3333
public onDropAllowed(args: IDropDroppedEventArgs): void {
@@ -42,6 +42,7 @@ export class GridDropIndicatorComponent implements AfterViewInit, OnDestroy {
4242
// remove the row that was dragged and place it onto its new location
4343
this.grid.deleteRow(this._draggedRow[this.grid.primaryKey]);
4444
this.data.splice(currRowIndex, 0, this._draggedRow);
45+
this.data = [...this.data];
4546
this.clearHighlightElement();
4647
}
4748

@@ -69,10 +70,10 @@ export class GridDropIndicatorComponent implements AfterViewInit, OnDestroy {
6970
for (const row of rowList) {
7071
const rowRect = row.nativeElement.getBoundingClientRect();
7172
if (
72-
cursorPosition.y > rowRect.top + window.scrollY &&
73-
cursorPosition.y < rowRect.bottom + window.scrollY &&
74-
cursorPosition.x > rowRect.left + window.scrollX &&
75-
cursorPosition.x < rowRect.right + window.scrollX
73+
cursorPosition.y > rowRect.top &&
74+
cursorPosition.y < rowRect.bottom &&
75+
cursorPosition.x > rowRect.left &&
76+
cursorPosition.x < rowRect.right
7677
) {
7778
// return the index of the targeted row
7879
return this.data.indexOf(this.data.find(r => r.ID === row.key));

src/app/grid/grid-row-pinning-drag/grid-row-pinning-drag.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class GridPinningDragSampleComponent implements OnInit {
2020
public pinningConfig: IPinningConfig = { rows: RowPinningPosition.Top };
2121

2222
constructor() {
23-
this.data = DATA;
23+
this.data = [...DATA];
2424
}
2525

2626
public ngOnInit() {
@@ -56,6 +56,7 @@ export class GridPinningDragSampleComponent implements OnInit {
5656
// remove the row that was dragged and place it onto its new location
5757
this.grid.deleteRow((args.dragData as RowType).key);
5858
this.data.splice(currRowIndex, 0, args.dragData.data);
59+
this.data = [...this.data];
5960
if (currentRow.pinned && !args.dragData.pinned) {
6061
this.grid.pinRow(args.dragData.key, currRowPinnedIndex);
6162
} else if (!currentRow.pinned && args.dragData.pinned) {
@@ -75,8 +76,8 @@ export class GridPinningDragSampleComponent implements OnInit {
7576
private getCurrentRowIndex(rowList, cursorPosition) {
7677
for (const row of rowList) {
7778
const rowRect = row.nativeElement.getBoundingClientRect();
78-
if (cursorPosition.y > rowRect.top + window.scrollY && cursorPosition.y < rowRect.bottom + window.scrollY &&
79-
cursorPosition.x > rowRect.left + window.scrollX && cursorPosition.x < rowRect.right + window.scrollX) {
79+
if (cursorPosition.y > rowRect.top && cursorPosition.y < rowRect.bottom &&
80+
cursorPosition.x > rowRect.left && cursorPosition.x < rowRect.right) {
8081
// return the index of the targeted row
8182
return this.data.indexOf(this.data.find((r) => r.ID === row.key));
8283
}
@@ -88,8 +89,8 @@ export class GridPinningDragSampleComponent implements OnInit {
8889
private getCurrentRowID(rowList: IgxRowDirective[], cursorPosition) {
8990
for (const row of rowList) {
9091
const rowRect = row.nativeElement.getBoundingClientRect();
91-
if (cursorPosition.y > rowRect.top + window.scrollY && cursorPosition.y < rowRect.bottom + window.scrollY &&
92-
cursorPosition.x > rowRect.left + window.scrollX && cursorPosition.x < rowRect.right + window.scrollX) {
92+
if (cursorPosition.y > rowRect.top && cursorPosition.y < rowRect.bottom &&
93+
cursorPosition.x > rowRect.left && cursorPosition.x < rowRect.right) {
9394
// return the ID of the targeted row
9495
return row.key;
9596
}

src/app/grid/grid-row-reorder-sample/grid-row-reorder.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,24 @@ export class GridRowReorderComponent {
1717
public data: any[];
1818

1919
constructor() {
20-
this.data = DATA;
20+
this.data = [...DATA];
2121
}
2222

2323
public onDropAllowed(args) {
2424
const event = args.originalEvent;
2525
const currRowIndex = this.getCurrentRowIndex(this.grid.rowList.toArray(),
2626
{ x: event.clientX, y: event.clientY });
2727
if (currRowIndex === -1) { return; }
28-
// remove the row that was dragged and place it onto its new location
2928
this.grid.deleteRow(args.dragData.key);
3029
this.data.splice(currRowIndex, 0, args.dragData.data);
30+
this.data = [...this.data];
3131
}
3232

3333
private getCurrentRowIndex(rowList: IgxRowDirective[], cursorPosition) {
3434
for (const row of rowList) {
3535
const rowRect = row.nativeElement.getBoundingClientRect();
36-
if (cursorPosition.y > rowRect.top + window.scrollY && cursorPosition.y < rowRect.bottom + window.scrollY &&
37-
cursorPosition.x > rowRect.left + window.scrollX && cursorPosition.x < rowRect.right + window.scrollX) {
38-
// return the index of the targeted row
36+
if (cursorPosition.y > rowRect.top && cursorPosition.y < rowRect.bottom &&
37+
cursorPosition.x > rowRect.left && cursorPosition.x < rowRect.right) {
3938
return this.data.indexOf(this.data.find((r) => r.ID === row.key));
4039
}
4140
}

0 commit comments

Comments
 (0)