Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add mutiple header rows using angular material table

Parameter 1: Time Period {{element.value}} Parameter 2: Gender {{element.gender}}

<ng-container matColumnDef="column3">
  <mat-header-cell *matHeaderCellDef rowspan="2"> Patients with Base Condition </mat-header-cell>
  <mat-cell *matCellDef="let element"> {{element.value}} </mat-cell>
</ng-container>

<ng-container matColumnDef="column4">
  <mat-header-cell *matHeaderCellDef> Patients with Outcome</mat-header-cell>
  <mat-cell *matCellDef="let element"> {{element.value}} </mat-cell>
</ng-container>

<ng-container matColumnDef="column5">
  <mat-header-cell *matHeaderCellDef class="ColumnDivider"> Prevelance </mat-header-cell>
  <mat-cell *matCellDef="let element" class="ColumnDivider"> {{element.value}} </mat-cell>
</ng-container>

<ng-container matColumnDef="column6">
  <mat-header-cell *matHeaderCellDef> Patients at Risk </mat-header-cell>
  <mat-cell *matCellDef="let element"> {{element.value}} </mat-cell>
</ng-container>

<ng-container matColumnDef="column7">
  <mat-header-cell *matHeaderCellDef> New Patients with Outcome </mat-header-cell>
  <mat-cell *matCellDef="let element"> {{element.value}} </mat-cell>
</ng-container>

<ng-container matColumnDef="column8">
  <mat-header-cell *matHeaderCellDef class="ColumnDivider"> Incidence Proportion </mat-header-cell>
  <mat-cell *matCellDef="let element" class="ColumnDivider"> {{element.value}} </mat-cell>
</ng-container>

<ng-container matColumnDef="column8">
  <mat-header-cell *matHeaderCellDef> Total Patient Years at Risk </mat-header-cell>
  <mat-cell *matCellDef="let element"> {{element.value}} </mat-cell>
</ng-container>

<ng-container matColumnDef="column10">
  <mat-header-cell *matHeaderCellDef class="myMarginLeft"> New Patients with Outcome </mat-header-cell>
  <mat-cell *matCellDef="let element" class="myMarginLeft"> {{element.value}} </mat-cell>
</ng-container>

<ng-container matColumnDef="column11">
  <mat-header-cell *matHeaderCellDef >Incidence Rate </mat-header-cell>
  <mat-cell *matCellDef="let element"> {{element.value}} </mat-cell>
</ng-container>

<ng-container *matHeaderRowDef="displayedColumns">
  <div class="mat-header-row header-group-row">
    <div class="mat-header-cell" role="columnheader"></div>
    <div class="mat-header-cell" role="columnheader"></div>
  </div>
  <mat-header-row></mat-header-row>
</ng-container>
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="getRecord(row)" [ngClass]="{'highlight': selectedRowIndex == row.inp_analysis_name}"></mat-row>

Multiple columns with a single column.

column1|column2|Column3|Column4|Column5|Column6|Column7|Column8 Column2.1|Column2.2|Column2.3 Column6.1|Column6.2

like image 307
v3nu Avatar asked Jun 23 '19 13:06

v3nu


People also ask

How do you set a table style with multiple header rows?

To apply the header row formatting to multiple rows in the table: after the table style is applied, select the rows you want included in the "header row" and on the Table tools > Layout tab, click Repeat Header Rows. If header row is ticked in Design tab > Table style options, you will see your header row formatting.

What is MatColumnDef in angular?

MatColumnDef extends CdkColumnDef Column definition for the mat-table. Defines a set of cells available for a table column.


1 Answers

An example of re-creating multiple header rows and cell grouping using colspan.

https://stackblitz.com/edit/angular-bklajw?file=app%2Ftable-basic-example.html

enter image description here

like image 147
rrr Avatar answered Oct 25 '22 17:10

rrr