Sahin
Sahin

Reputation: 97

Drag and Drop with sorting it is possible in Angular Material?

Scenario :

Example : https://stackblitz.com/edit/angular-by5l4g

App URL : https://angular-by5l4g.stackblitz.io

Drag and Drop and Sorting

Upvotes: 1

Views: 9004

Answers (1)

Abhishek Kumar
Abhishek Kumar

Reputation: 2539

Demo with only div draggable from the icon

Application Code : https://stackblitz.com/edit/angular-drag-and-drop-example?file=src/app/app.component.ts

Approach :

  • Change <i class="material-icons">reorder</i> to
    <i class="material-icons" cdkDragHandle >reorder</i>
  • Used cdkDragHandle to make that icon draggable, and removed the cursor: move from div, and applied it to <i> tag.


Update 1 (according to checkbox question):

  • another similar <i> tag is kept as mask which will not allow drag start if checkbox is not checked, and on checkbox check we enable that mask to go away, so that the div is draggable from the main <i> tag.

Update 2 (according to delete and add question):

  • added delete and add functionality also.

Upvotes: 4

Related Questions