This is because the whole component (mat-header-cell
) gets disabled, which disables the click event, which in turn makes the cdkDrag
events not fire at all.
While it's a bit ugly solution, you can conditionally switch the template of the mat-header-cell to either have or not have the mat-sort-header directive. Then you don't have to fall back to the [disabled]
input:
<ng-container *ngIf="column.canSort">
<mat-header-cell *matHeaderCellDef
cdkDropList
cdkDropListLockAxis="x"
cdkDropListOrientation="horizontal"
(cdkDropListDropped)="dropListDropped($event, i)"
cdkDrag
(cdkDragStarted)="dragStarted($event, i)"
[cdkDragData]="{name: column.field, columIndex: i}" mat-sort-header>
{{ column.field }}
</mat-header-cell>
</ng-container>
<ng-container *ngIf="!column.canSort">
<mat-header-cell *matHeaderCellDef
cdkDropList
cdkDropListLockAxis="x"
cdkDropListOrientation="horizontal"
(cdkDropListDropped)="dropListDropped($event, i)"
cdkDrag
(cdkDragStarted)="dragStarted($event, i)"
[cdkDragData]="{name: column.field, columIndex: i}">
{{ column.field }}
</mat-header-cell>
</ng-container>
In the above example I've added the canSort property on the column, but of course you can use the above predicate of yours ("i%2==0"
).
Hope this helps.