Angular Material 表格不允许为列禁用拖放标志。

huangapple go评论65阅读模式
英文:

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).

  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>


# 答案1
**得分**: 1

If you would like to disable sorting entire table, you can set `cdkDropListSortingDisabled`.

```html
&lt;table
    cdkDropList
    cdkDropListOrientation=&quot;horizontal&quot;
    (cdkDropListDropped)=&quot;drop($event)&quot;
    [cdkDropListSortingDisabled]=&quot;!editMode&quot;
&gt;

Or you can set cdkDragDisabled to child elements.

&lt;table
       :
    (cdkDropListDropped)=&quot;drop($event)&quot;
&gt;
  &lt;tr [cdkDragDisabled]=&quot;!editMode&quot;&gt;
  &lt;/tr&gt;
&lt;/table&gt;
英文:

If you would like to disable sorting entire table, you can set cdkDropListSortingDisabled.

&lt;table

    cdkDropList
    cdkDropListOrientation=&quot;horizontal&quot;
    (cdkDropListDropped)=&quot;drop($event)&quot;
    [cdkDropListSortingDisabled]=&quot;!editMode&quot;
&gt;

Or you can set cdkDragDisabled to child elements.

&lt;table
       :
    (cdkDropListDropped)=&quot;drop($event)&quot;
&gt;
  &lt;tr [cdkDragDisabled]=&quot;!editMode&quot;&gt;
  &lt;/tr&gt;
&lt;/table&gt;

huangapple
  • 本文由 发表于 2023年6月13日 05:05:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76460335.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定