-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ngrid/drag): support row reordering in virtual scroll
- Loading branch information
1 parent
95ea261
commit 5a24eec
Showing
9 changed files
with
120 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
libs/ngrid/drag/src/lib/drag-and-drop/row/row-drop-list-ref.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { PblNgridExtensionApi } from '@pebula/ngrid'; | ||
import { PblDropListRef } from '../core/drop-list-ref'; | ||
import { PblNgridRowReorderPluginDirective } from './row-reorder-plugin'; | ||
import { takeUntil } from 'rxjs/operators'; | ||
import { Type } from '@angular/core'; | ||
|
||
export type _PblDropListRef = Omit<PblDropListRef<PblNgridRowReorderPluginDirective<any>>, '_getItemIndexFromPointerPosition' | 'start'> & { | ||
start(): void; | ||
_getItemIndexFromPointerPosition(item: PblRowDropListRef, pointerX: number, pointerY: number, delta?: {x: number, y: number}): number | ||
}; | ||
|
||
export const _PblDropListRef = () => { return PblDropListRef as any as Type<_PblDropListRef>; }; | ||
|
||
export class PblRowDropListRef<T = any> extends _PblDropListRef() { | ||
|
||
gridApi: PblNgridExtensionApi<T>; | ||
|
||
private scrollDif = 0; | ||
|
||
_getItemIndexFromPointerPosition(item: PblRowDropListRef, pointerX: number, pointerY: number, delta?: {x: number, y: number}): number { | ||
return super._getItemIndexFromPointerPosition(item, pointerX, pointerY - this.scrollDif, delta); | ||
} | ||
|
||
start(): void { | ||
super.start(); | ||
this.scrollDif = 0; | ||
if (this.gridApi.grid.viewport.enabled) { | ||
const initialTop = this.gridApi.grid.viewport.measureScrollOffset(); | ||
this.gridApi.grid.viewport.elementScrolled() | ||
.pipe(takeUntil(this.dropped)) | ||
.subscribe(() => { | ||
this.scrollDif = this.gridApi.grid.viewport.measureScrollOffset() - initialTop; | ||
}); | ||
} | ||
} | ||
|
||
} | ||
|
||
export function patchDropListRef<T = any>(dropListRef: PblDropListRef<PblNgridRowReorderPluginDirective<T>>, gridApi: PblNgridExtensionApi<T>) { | ||
try { | ||
Object.setPrototypeOf(dropListRef, PblRowDropListRef.prototype); | ||
} catch (err) { | ||
(dropListRef as any)._getItemIndexFromPointerPosition = PblRowDropListRef.prototype._getItemIndexFromPointerPosition; | ||
dropListRef.start = PblRowDropListRef.prototype.start; | ||
} | ||
|
||
(dropListRef as unknown as PblRowDropListRef).gridApi = gridApi; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters