英文:
Angular Material Table not allowing for drag and drop disable flag for columns
问题
我正在使用Angular材料表格,并进行了以下设置:
I am using angular material table with some of the following settings:
```html
<table
mat-table
[ngStyle]="{'height': '600px'}"
[dataSource]="items"
multiTemplateDataRows
matSort
(matSortChange)="sortData($event)"
[matSortActive]="componentSettings.header.sort"
[matSortDirection]="componentSettings.header.order"
cdkDropList
cdkDropListOrientation="horizontal"
(cdkDropListDropped)="drop($event)"
[cdkDragDisabled]="!editMode"
>
我遇到了以下错误:
I am getting the following error:
template.html:26 NG0303: Can't bind to 'cdkDragDisabled' since it isn't a known property of 'table' (used in the 'TableDataComponent' component template).
1. If 'table' is an Angular component and it has the 'cdkDragDisabled' input, then verify that it is a part of an @NgModule where this component is declared.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
有没有办法使用布尔标志禁用列的拖放?
Is there a way to disable column drag and drop with a boolean flag?
<details>
<summary>英文:</summary>
I am using angular material table with some of the following settings:
<table
mat-table
[ngStyle]="{'height': '600px'}"
[dataSource]="items"
multiTemplateDataRows
matSort
(matSortChange)="sortData($event)"
[matSortActive]="componentSettings.header.sort"
[matSortDirection]="componentSettings.header.order"
cdkDropList
cdkDropListOrientation="horizontal"
(cdkDropListDropped)="drop($event)"
[cdkDragDisabled]="!editMode"
>
I am getting the following error:
template.html:26 NG0303: Can't bind to 'cdkDragDisabled' since it isn't a known property of 'table' (used in the 'TableDataComponent' component template).
- If 'table' is an Angular component and it has the 'cdkDragDisabled' input, then verify that it is a part of an @NgModule where this component is declared.
- To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
Is there a way to disable column drag and drop with a boolean flag?
</details>
# 答案1
**得分**: 1
If you would like to disable sorting entire table, you can set `cdkDropListSortingDisabled`.
```html
<table
cdkDropList
cdkDropListOrientation="horizontal"
(cdkDropListDropped)="drop($event)"
[cdkDropListSortingDisabled]="!editMode"
>
Or you can set cdkDragDisabled
to child elements.
<table
:
(cdkDropListDropped)="drop($event)"
>
<tr [cdkDragDisabled]="!editMode">
</tr>
</table>
英文:
If you would like to disable sorting entire table, you can set cdkDropListSortingDisabled
.
<table
cdkDropList
cdkDropListOrientation="horizontal"
(cdkDropListDropped)="drop($event)"
[cdkDropListSortingDisabled]="!editMode"
>
Or you can set cdkDragDisabled
to child elements.
<table
:
(cdkDropListDropped)="drop($event)"
>
<tr [cdkDragDisabled]="!editMode">
</tr>
</table>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论