0

My material table is with Drag & Drop enable. I want add togle button to Disable/Enable this mode.

My HTML template:

<table mat-table #table [dataSource]="dataSource | periodicElementFilter:periodicElementFilter" class="mat-elevation-z8"
  cdkDropList
  (cdkDropListDropped)="dropTable($event)">
    ...
</table>

My typeScript component:

enableDragDropMode(event: MatSlideToggleChange) {
  // ???
}

enter image description here

Demo online HERE

Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154

3 Answers3

4

I find solution HERE:

enter image description here

<table mat-table #table [dataSource]="dataSource | periodicElementFilter:periodicElementFilter" class="mat-elevation-z8"
  cdkDropList
  (cdkDropListDropped)="dropTable($event)"
  [cdkDropListDisabled]="dragDisabled">

And

enableDragDropMode(event: MatSlideToggleChange) {
  this.dragDisabled = !event.checked
}

And upgrade Angular to 8.0.3+ and "@angular/material": "8.0.1+"

Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154
2

You can use @Input('cdkDropListDisabled'), which is boolean type and manage it by changing this input value.

Add below code to your table:

[cdkDropListDisabled]="yourBooleanProperty"

Then inside your enableDragDropMode function change yourBooleanProperty value based on event :)

Hope it helps!

Ashiv3r
  • 894
  • 4
  • 14
  • 28
0

You can add this attribute [cdkDragDisabled] = "true". Reference link https://material.angular.io/cdk/drag-drop/api

luqman ahmad
  • 171
  • 1
  • 7