简体   繁体   English

如何在 Angular 中将 Mat Table 网格扩展到第三级?

[英]How to expand Mat Table grid to the thrid level in Angular?

I have created a Mat-Table with nested grid with a nested json .我创建了一个带有嵌套网格的 Mat-Table 和一个嵌套的 json 。 It has 2 grids for now .它现在有 2 个网格。 But now i have a requirement where i need an additional nested grid inside .但现在我有一个要求,我需要一个额外的嵌套网格。

I tried to replicate what is done for the second level grid to generate the third level grid but the "ExpandedElements" array throws an error while generating the third level grid .我试图复制为第二级网格所做的工作以生成第三级网格,但“ExpandedElements”数组在生成第三级网格时引发错误。

My updated JSON looks like -我更新的 JSON 看起来像 -

{
name: 'Mason',
email: 'mason@test.com',
phone: '9864785214',
addresses: [
  {
    street: 'Street 1',
    zipCode: '78542',
    city: 'Kansas',
    comments: [
      {
        commenID: 1,
        comment: 'Test',
        commentStatus: 'Open'
      },
      {
        commenID: 2,
        comment: 'Test',
        commentStatus: 'Open'
      },{
        commenID: 3,
        comment: 'Test',
        commentStatus: 'Closed'
      },
    ]
  },

I want the comments to be an internal grid under address grid .我希望评论成为 address grid 下的内部网格。

I have the 2 grids ready with the json in the stackblitz link -我在 stackblitz 链接中准备了 2 个网格和 json -

https://stackblitz.com/edit/angular-nested-mat-table-sia2jn?file=app%2Ftable-expandable-rows-example.ts https://stackblitz.com/edit/angular-nested-mat-table-sia2jn?file=app%2Ftable-expandable-rows-example.ts

Can anyone help me how to proceed with the third level of grid ?谁能帮助我如何进行第三级网格?

Thanks谢谢

Edited your Stackblitz for a working example: https://stackblitz.com/edit/angular-nested-mat-table-triplenested?file=app/table-expandable-rows-example.html编辑您的 Stackblitz 作为一个工作示例: https ://stackblitz.com/edit/angular-nested-mat-table-triplenested?file=app/table-expandable-rows-example.html

Added the additional table and added bools directly on the datasource to show what is expanded and not (instead of the list functions).添加了附加表并直接在数据源上添加了 bool 以显示展开的内容和未展开的内容(而不是列表功能)。 Also using simple arrays instead of dataSource.还使用简单数组而不是数据源。 :) :)


On the div inside the table data:在表数据内的 div 上:

<div class="example-element-detail" [@detailExpand]="element?.expanded"  *ngIf="element?.expanded">

On the row definition:在行定义上:

<tr mat-row *matRowDef="let element; columns: columnsToDisplay;"
    [class.example-element-row]="element.addresses?.length" [class.example-expanded-row]="element?.expanded"
    (click)="element.expanded = !element?.expanded">
</tr>

It checks for the key expanded on element.它检查元素上扩展的键。 The question mark is a null check, so if the key does not exist - element?.expanded returns undefined.问号是一个空检查,所以如果键不存在 - element?.expanded 返回 undefined。

Also, when clicking the row, element.expanded is set to !element?.expanded.此外,当单击该行时,element.expanded 被设置为 !element?.expanded。 When clicking the first time, element?.expanded is undefined and adding an exclamation point in front of that inverts it - essentially setting it to true.当第一次点击时, element?.expanded 是未定义的,在它前面添加一个感叹号会反转它 - 基本上将它设置为 true。 Next time you click it will be set to the opposite of true - which is false.下次单击时,它将被设置为 true 的相反值 - 这是 false。 :) :)

There is no need to add it to the JSON directly, the bools will be added as needed when clicking the table.不需要直接添加到JSON中,点击表格时会根据需要添加bool。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Angular中导出多层垫子网格到excel? - How to export multi level mat grid to excel in Angular? 单击 Angular 中的一行时,如何在 Mat Table 中展开多行? - How to expand multiple rows in a Mat Table on clicking of a row in Angular? 折叠和折叠手风琴垫表的图标-Angular - Expand and collapse icons for mat table with accordion - Angular 如何为Mat-table创建一个Expand All Button,以使其在Angular 8中扩展表中的每一行? - How to create an Expand All Button for Mat-table so that it expands every row in the table in Angular 8? 如何使用带条件的 mat 表扩展行 - How to expand a row using mat table with a condition 如何添加箭头图标以展开和折叠Angular Mat-Table中具有可扩展行的任何行? - How to add arrow icons to expand and collapse any row in Angular Mat-Table with Expandable Rows? 如何在剑道网格中自动扩展细节以获取角度 - how to automatically expand detail in kendo grid for angular 如何在Syncfusion Angular Grid中扩展像元? - How to expand a cell in a Syncfusion Angular Grid? Angular mat-table 可扩展行:如何自动扩展第一行? 以及如何控制我何时折叠它? - Angular mat-table expandable rows: how can i automatically expand first row? and how to control when i collapsed it? 在 typescript 中解析多级 json 并在 angular 中填充 Mat-table - Parse multi level json in typescript and populate Mat-table in angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM