23

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

3
  • 3
    here you can find official example for mat-table with multiple headers. Commented Jun 23, 2019 at 18:50
  • Since I am using angular 5 it doesn't work using the above mentioned solution. Commented Jun 24, 2019 at 8:51
  • I found a solution to this problem ;multi-header table Commented Feb 17, 2022 at 9:28

2 Answers 2

21

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

Sign up to request clarification or add additional context in comments.

5 Comments

How we can subgroup in the second group again? Like thirdgroup which have weight and symbol while forth group have some other parameter like height?
I got [style.text-align]="center" not found error in Angular 11.
how to add third header lets say "group" which is grouping of "First Group" and "Secoind Group"?
i am not able to do something like ` <tr mat-header-row *matHeaderRowDef="big-header-group"></tr> <tr mat-header-row *matHeaderRowDef="['header-row-first-group', 'header-row-second-group']"></tr> <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>`
[attr.colspan] doesn't work for me
0

The official solution was not useful for me because I needed the secondary header row to span all columns (this way I can use a separate component using content projection)

My solution is to create a SecondaryHeaderComponent which extends from CdkHeaderRow:

@Component({
   selector: 'mat-secondary-header-row',
   standalone: true,
   template: `<ng-content></ng-content>`
})
export class SecondaryHeaderComponent extends CdkHeaderRow {}

Which can then be used like this (for example beneath the mat-header-row element):

<mat-secondary-header-row *matHeaderRowDef="[]; sticky: true">
   <p>2nd header row content!</p>
</mat-secondary-header-row>

One quirk I came across is that the table contents are still visible beneath the (sticky) secondary header row.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.