angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.38k stars 6.75k forks source link

drag-drop + virtual scroll: Draggable item loses its position when new list item is rendered in the DOM as a result of virtual scrollingbug #22406

Closed amitapatiyal24 closed 3 years ago

amitapatiyal24 commented 3 years ago

Reproduction

Use StackBlitz to reproduce your issue:

Steps to reproduce:

  1. <cdk-virtual-scroll-viewport  cdkDropList  itemSize="25" scrollViewport cdkDropList

    class="viewport ps blue-scrollbar member-box" [perfectScrollbar] (scrolledIndexChange)="nextBatch()" [cdkDropListData] = "selectedDimension?.memberSelections" (cdkDropListDropped)="onDrag($event)" [style.height]="memberHeight">
    <li *cdkVirtualFor="let members of memberSelections " cdkDrag>{{member}}

  2. </ul

  3. public onDrag(event: CdkDragDrop<string[]>): void { if (event.previousContainer === event.container) { const PREV_IND_WITH_OFFSET: number = this.range ? this.range.start + event.previousIndex : event.previousIndex; const CUR_IND_WITH_OFFSET: number = this.range ? this.range.start + event.currentIndex : event.currentIndex ; moveItemInArray( this.selectedDimension.memberSelections, PREV_IND_WITH_OFFSET, CUR_IND_WITH_OFFSET); this.memberSelections = [...this.memberSelections]; } else { transferArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex); } this.val.emit(false); } public nextBatch(){ this.virtualForOf.viewChange.subscribe((range: ListRange) => this.range = range); console.log(this.range); }

Expected Behavior

What behavior were you expecting to see? list drag and drop for virtual scroll with a large dataset. e.g.(1000 of records)

Actual Behavior

What behavior did you actually see? I am using CDK virtual scroll and CDK drag/drop together for rendering the large list. When I am doing the drag and drop in the middle of the list, the dragged item is coming back to its original position. I have tried to solve this issue using the range, but still not able to get the expected result.

Environment

angular11

crisbeto commented 3 years ago

We don't currently support drag&drop with virtual scrolling. Closing as a duplicate of https://github.com/angular/components/issues/10122.

angular-automatic-lock-bot[bot] commented 3 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.