Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable sort in a CdkDropList using angular cdk v7.0.0+

I'm creating two CdkDropList objects and the dragging and dropping functionalities are working fine, my problem is that I would like to disable the sorting while I'm dragging in the first list. Let's say I have List A and List B. I'm dragging from A to B, I would like to disable the sorting while I'm over List A. In other words, I just want the drag n drop functionality, not the sorting. Can I disable that?

like image 383
Leslie Morejon Avatar asked Nov 19 '18 18:11

Leslie Morejon


2 Answers

It's implemented now in the drag & drop module of Angular Material 8 > see Disabled sorting

like image 130
Lord Midi Avatar answered Nov 20 '22 18:11

Lord Midi


I can do it simply adding a css property to the draggable div. I don't know that is the best solution, but, this work for me:

html:

<div cdkDropList>
    <div class="item-draggable" *ngFor="let item of items" cdkDrag>
        <span>{{item.label}}</span>
    </div>
</div>

css:

.item-draggable {
  transform: none !important;
}

UPDATE 10/28/2020

Angular material implemnt this with @Input sortingDisabled -> https://material.angular.io/cdk/drag-drop/api

like image 2
Sergio Santiago Pérez Avatar answered Nov 20 '22 20:11

Sergio Santiago Pérez