Search code examples
angulartypescriptangular-materialangular-cdk

Allow horizontal positioning in cdkDropList


In my application I have multiple rows, within those rows are "blocks" that can be dragged between rows which works perfectly.

However, In addition to dragging between rows I'd like to be able to freely position them horizontally as well.

enter image description here

When adding cdkDropListGroup and cdkDroplist, all elements are automatically left aligned.

For example; I'd like the blue "block" to start where the purple one ends using cdkDragDrop.


Solution

  • This, unfortunately, is not possible using cdkDropListGroup. The documentation specifically states elements can not be freely dragged around in a cdkDropList.

    When outside of a cdkDropList element, draggable elements can be freely moved around the page.

    You could set an initial value using cdkDragFreeDragPosition and snap the object to a grid with the (cdkDragEnded) event.