单击按钮展开“角度材料”行

Skydev

单击按钮时,我试图使我的Angular Material数据表在行上展开。这是我的代码和stackblitz示例。当前,它在列内展开,但是当用户单击切换按钮时,我正在尝试扩展行。

的HTML

<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">    
  <ng-container matColumnDef="title">
    <th mat-header-cell *matHeaderCellDef> Title </th>
    <td mat-cell *matCellDef="let element"> {{element.title}} </td>
  </ng-container>

  <ng-container matColumnDef="location">
    <th mat-header-cell *matHeaderCellDef> City </th>
    <td mat-cell *matCellDef="let element"> {{element.location.city}} </td>
  </ng-container>

  <ng-container matColumnDef="startDate">
    <th mat-header-cell *matHeaderCellDef> Start Date </th>
    <td mat-cell *matCellDef="let element"> {{element.startDate}} </td>
  </ng-container>

  <ng-container matColumnDef="deviceType">
    <th mat-header-cell *matHeaderCellDef> Device Type </th>
    <td mat-cell *matCellDef="let element"> {{element.deviceType}} </td>
  </ng-container>

  <ng-container matColumnDef="status">
    <th mat-header-cell *matHeaderCellDef> Status </th>
    <td mat-cell *matCellDef="let element"> {{element.status}} </td>
  </ng-container>

  <ng-container matColumnDef="expand">
    <th mat-header-cell *matHeaderCellDef> View More </th>
    <td mat-cell *matCellDef="let element; let i = index">
      <div class="example-element-detail" (click)="toggleFloat(i)">View</div>
      <div *ngIf="expanded[i] == true"> {{element.contributorProfiles}} </div>
    </td>
  </ng-container>

  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>

TS

dataSource看起来像这样

[
  {
    "title": "bob",
    "codes": [
      "Basketball"
    ],
    "description": null,
    "brief": "asdas",
    "locationId": "9614632c-d64d-4bf3-bb8f-5c38919f221c",
    "startDate": "2020-07-08T00:00:00.000+0000",
    "endDate": "2020-07-10T23:00:00.000+0000",
    "submissionDueDate": "2020-08-26T23:59:59.000+0000",
    "workAcceptanceDate": "2020-08-26T23:59:59.000+0000",
    "deviceType": "Photography",
    "photography": {
      "minimumDpi": 300,
      "shortestSideLength": 2800
    },
    "videography": null,
    "fees": 22,
    "accreditationRequired": false,
    "accreditationReason": null,
    "subjects": "test",
    "editors": null,
    "additionalEditorInformation": null,
    "imageId": null,
    "id": "b6b99931-c6a3-476a-8c3a-9e2535823c13",
    "status": "Created",
    "createdBy": {
      "id": "7dfebb6b-dc83-4d5b-a010-2c5807b0e979",
      "email": "[email protected]",
      "firstname": "Bhavic",
      "surname": "Naran",
      "cell": null,
      "status": "ACTIVE",
      "requestedOn": null
    },
    "location": {
      "id": "9614632c-d64d-4bf3-bb8f-5c38919f221c",
      "country": "Bhutan",
      "city": "Lhuentse"
    },
    "editorProfiles": [
      {
        "id": "7dfebb6b-dc83-4d5b-a010-2c5807b0e979",
        "email": "[email protected]",
        "firstname": "Bhavic",
        "surname": "Naran",
        "cell": null,
        "status": "ACTIVE",
        "requestedOn": null
      }
    ],
    "contributorProfiles": []
  },
  {
    "title": "tester kalpesh",
    "codes": [
      "Basketball"
    ],
    "description": null,
    "brief": "123",
    "locationId": "aec466d9-9fb6-4718-9b1f-5fad429f7145",
    "startDate": "2020-06-24T00:00:00.000+0000",
    "endDate": "2020-07-03T23:00:00.000+0000",
    "submissionDueDate": "2020-08-26T23:59:59.000+0000",
    "workAcceptanceDate": "2020-08-26T23:59:59.000+0000",
    "deviceType": "Photography",
    "photography": {
      "minimumDpi": 300,
      "shortestSideLength": 2800
    },
    "videography": null,
    "fees": 55,
    "accreditationRequired": false,
    "accreditationReason": "none",
    "subjects": "55",
    "editors": null,
    "additionalEditorInformation": null,
    "imageId": null,
    "id": "3fdf9972-9b21-4a6e-b650-4141f5c6809e",
    "status": "Assigned",
    "createdBy": {
      "id": "7dfebb6b-dc83-4d5b-a010-2c5807b0e979",
      "email": "[email protected]",
      "firstname": "Bhavic",
      "surname": "Naran",
      "cell": null,
      "status": "ACTIVE",
      "requestedOn": null
    },
    "location": {
      "id": "aec466d9-9fb6-4718-9b1f-5fad429f7145",
      "country": "South Africa",
      "city": "Johannesburg"
    },
    "editorProfiles": [
      {
        "id": "7dfebb6b-dc83-4d5b-a010-2c5807b0e979",
        "email": "[email protected]",
        "firstname": "Bhavic",
        "surname": "Naran",
        "cell": null,
        "status": "ACTIVE",
        "requestedOn": null
      }
    ],
    "contributorProfiles": [
      {
        "id": "95ac8466-8d98-47ab-95f8-24eb7b7cc27b",
        "email": "[email protected]",
        "firstname": "Kalpesh",
        "surname": "Mithal",
        "cell": "0884441122",
        "appliedStatus": "Created"
      }
    ]
  }
]

Stackblitz示例在这里

https://stackblitz.com/edit/angular-hvcf5z

托马斯·维赞特(Tomasz Vizaint)

试试这个,希望对您有所帮助。在您首先丢失“ multiTempalteDataRows”之后,在第二个列定义中使用此

displayedColumns = ['title','location','startDate','deviceType','status', 'more'];

最后添加第三行以获取详细信息

<tr mat-row *matRowDef="let row; columns: ['expanded']" class="example-detail-row"></tr>

HTML

<table mat-table [dataSource]="dataSource" class="mat-elevation-z8" multiTemplateDataRows>

  <ng-container matColumnDef="title">
    <th mat-header-cell *matHeaderCellDef> Title </th>
    <td mat-cell *matCellDef="let element"> {{element.title}} </td>
  </ng-container>

  <ng-container matColumnDef="location">
    <th mat-header-cell *matHeaderCellDef> City </th>
    <td mat-cell *matCellDef="let element"> {{element.location.city}} </td>
  </ng-container>

  <ng-container matColumnDef="startDate">
    <th mat-header-cell *matHeaderCellDef> Start Date </th>
    <td mat-cell *matCellDef="let element"> {{element.startDate}} </td>
  </ng-container>

  <ng-container matColumnDef="deviceType">
    <th mat-header-cell *matHeaderCellDef> Device Type </th>
    <td mat-cell *matCellDef="let element"> {{element.deviceType}} </td>
  </ng-container>

  <ng-container matColumnDef="status">
    <th mat-header-cell *matHeaderCellDef> Status </th>
    <td mat-cell *matCellDef="let element"> {{element.status}} </td>
  </ng-container>

  <ng-container matColumnDef="more">
    <th mat-header-cell *matHeaderCellDef> More </th>
    <td mat-cell *matCellDef="let element"> <button (click)="expanded = expanded === element ? null : element">More</button> </td>
  </ng-container>

<ng-container matColumnDef="expanded">
   <td mat-cell *matCellDef="let element">
      <div class="example-element-detail" [@detailExpand]="element == expanded ? 'expanded' : 'collapsed'">
          <span> this is your incredible expandable details </span>
          </div>
    </td>
</ng-container>

  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
  <tr mat-row *matRowDef="let row; columns: ['expanded']" class="example-detail-row"></tr>
</table>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Jquery 在按钮单击时展开隐藏的表格行

来自分类Dev

角度-仅在单击的行上启用按钮

来自分类Dev

单击行展开并折叠

来自分类Dev

捕获输入值并在带有角度材料输入的按钮单击时显示该值

来自分类Dev

角度材料-在特定的垫子展开面板上设置边框颜色

来自分类Dev

展开和折叠按钮上的第一行,单击“目标-C”。

来自分类Dev

展开和折叠按钮上的第一行,单击“目标-C”。

来自分类Dev

角材料表:单击按钮后如何传递/提交选定的行?

来自分类Dev

如何将表的选定行值传递给按钮单击事件 - 材料设计 - Angular 6

来自分类Dev

Android展开圆形动画以实现按钮单击

来自分类Dev

单击按钮展开tableview单元格

来自分类Dev

角度数据表,配置行单击事件时无法单击行按钮

来自分类Dev

展开时具有可展开行背景颜色的角度材料表

来自分类Dev

如果打开则隐藏子行并在单击展开所有按钮时切换所有子行

来自分类Dev

鼠标单击展开表格行

来自分类Dev

鼠标单击展开表格行

来自分类Dev

通过按钮展开和折叠行

来自分类Dev

以编程方式触发角度材料图标按钮上的波纹

来自分类Dev

单击“阅读更多”按钮或链接时如何展开文本?

来自分类Dev

单击打印按钮后,Colspan gridview展开更多列

来自分类Dev

单击按钮展开选择列表并隐藏选择

来自分类Dev

c#WPF,如何在单击按钮时展开表格?

来自分类Dev

单击“阅读更多”按钮或链接时如何展开文本?

来自分类Dev

单击按钮展开选择列表,然后隐藏选择

来自分类Dev

单击“展开”按钮后如何设置固定表格的大小

来自分类Dev

角度UI网格单击行

来自分类Dev

单击按钮更新角度视图模型

来自分类Dev

单击按钮时更改角度指令

来自分类Dev

单击按钮以一定角度旋转

Related 相关文章

  1. 1

    Jquery 在按钮单击时展开隐藏的表格行

  2. 2

    角度-仅在单击的行上启用按钮

  3. 3

    单击行展开并折叠

  4. 4

    捕获输入值并在带有角度材料输入的按钮单击时显示该值

  5. 5

    角度材料-在特定的垫子展开面板上设置边框颜色

  6. 6

    展开和折叠按钮上的第一行,单击“目标-C”。

  7. 7

    展开和折叠按钮上的第一行,单击“目标-C”。

  8. 8

    角材料表:单击按钮后如何传递/提交选定的行?

  9. 9

    如何将表的选定行值传递给按钮单击事件 - 材料设计 - Angular 6

  10. 10

    Android展开圆形动画以实现按钮单击

  11. 11

    单击按钮展开tableview单元格

  12. 12

    角度数据表,配置行单击事件时无法单击行按钮

  13. 13

    展开时具有可展开行背景颜色的角度材料表

  14. 14

    如果打开则隐藏子行并在单击展开所有按钮时切换所有子行

  15. 15

    鼠标单击展开表格行

  16. 16

    鼠标单击展开表格行

  17. 17

    通过按钮展开和折叠行

  18. 18

    以编程方式触发角度材料图标按钮上的波纹

  19. 19

    单击“阅读更多”按钮或链接时如何展开文本?

  20. 20

    单击打印按钮后,Colspan gridview展开更多列

  21. 21

    单击按钮展开选择列表并隐藏选择

  22. 22

    c#WPF,如何在单击按钮时展开表格?

  23. 23

    单击“阅读更多”按钮或链接时如何展开文本?

  24. 24

    单击按钮展开选择列表,然后隐藏选择

  25. 25

    单击“展开”按钮后如何设置固定表格的大小

  26. 26

    角度UI网格单击行

  27. 27

    单击按钮更新角度视图模型

  28. 28

    单击按钮时更改角度指令

  29. 29

    单击按钮以一定角度旋转

热门标签

归档