Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 7 Drag&Drop nested lists with native CDK

I am using native Angular 7 Drag&Drop provided by @angular/cdk/drag-drop.

Basically, I just need to create one sortable list inside another one as in the code below:

<div class="external-list" cdkDropList (cdkDropListDropped)="drop1($event)">
  <div class="external-item" cdkDrag *ngFor="let item of items">
    {{item.header}}
    <div class="internal-list" cdkDropList (cdkDropListDropped)="drop2($event)">
      <div class="internal-item" cdkDrag *ngFor="let row of item.rows">
        {{row}}
      </div>
    </div>
  </div>
</div>

This is a very schematic example just to demonstrate the purpose.

The problem is when I try dragging the inner items outer ones are dragged instead.

How can I solve this without resorting to 3rd-party packages?

like image 451
Andrii Romanchak Avatar asked Jun 10 '26 05:06

Andrii Romanchak


1 Answers

I think you will need to use a drag handle (cdkDragHandle on an element inside cdkDrag), at least for the parent list.

https://material.angular.io/cdk/drag-drop/overview#customizing-the-drag-area-using-a-handle

like image 101
user3910610 Avatar answered Jun 11 '26 19:06

user3910610



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!