Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

Angular - print additional TDs inside a component table, based on header

i'm trying to build a semi-automatic table with angular 10: i can give to it an object of data, an array of strings with the columns and i would like to include some html inside the tag.

The array of strings may include values that are not keys of the data, but instead they can refer to a piece of html that i wrote between the ed-table tags.

Usage of table:

<ed-table [sourceData]="table" [columns]="tableColumn">
    <div *name="COLUMNNAME"></div> <!-- what i want to achieve -->
</ed-table>

Table component: right now i'm trying to print a cell that should contains the element, but i honestly can't figure out how.

<table class="table">
  <thead *ngIf="showHeader">
  <tr>
    <th *ngFor="let col of columns">
      {{col}}
    </th>
  </tr>
  </thead>
  <tbody>
  <tr *ngFor="let data of sourceData"
      ed-table-row
      [data]="data"
      [columns]="columns">
    <span *name="let name">
      {{name}}
    </span>
  </tr>
  </tbody>
</table> 

table row:

<td *ngFor="let col of columns">
  <ng-template [ngIf]="data[col] !== undefined">
    {{data[col]}}
  </ng-template>
  <ng-template [ngIf]="data[col] === undefined">
    <ng-template [ngTemplateOutlet]="templateRef" [ngTemplateOutletContext]="{$implicit: data[col]}"></ng-template>
  </ng-template>
</td>

 

Table row ts:

export class TableRowComponent {
  @Input() data: any;
  @Input() columns: string[];
  @ContentChild(TemplateRef) templateRef: TemplateRef<any>;

  constructor() {
  }

} 

Can someone give me some hints? Thanks!

question from:https://stackoverflow.com/questions/66047055/angular-print-additional-tds-inside-a-component-table-based-on-header

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...