liveBook · Manning

matColumnDef

As explained in Pro Angular 16

The matColumnDef attribute identifies an Angular Material table column definition applied to a container of header and data cells.

The matColumnDef attribute names a custom Angular Material table column. Apply it to an ng-container holding the header and data-cell templates for that column. section 28.2.2

Use matColumnDef when a column needs more than direct property display:

  • Place th mat-header-cell and td mat-cell elements inside the container. section 28.2.2
  • Use matHeaderCellDef and matCellDef to define the header and cell content. section 28.2.2
  • Format or compose values with an implicit row value, such as formatting item.price with the currency pipe. section 28.2.2

Custom price column

A price column can format each row value instead of displaying it unchanged: <ng-container matColumnDef="price"> <th mat-header-cell *matHeaderCellDef>Price</th> <td mat-cell *matCellDef="let item">{{item.price | currency:"USD"}}</td> </ng-container>

How Pro Angular 16 covers it

How deep it goes
Explains container placement, header and cell directives, implicit row values, and formatting, without descending into table internals.
Examples
Uses price formatting and action buttons as concrete custom-column examples.
What it assumes
Assumes Angular template syntax and table concepts while clarifying concise directive syntax and implicit values.
What you can do after
Operate/configure it to create formatted or multi-property Angular Material table columns.
How it connects
Connects Angular Material tables with mat-header-cell, mat-cell, matHeaderCellDef, matCellDef, and row templates.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.