Skip to content

A quick example showing how to make a wrapper component around the CDK Table or MatTable with projected columns.

Notifications You must be signed in to change notification settings

areknow/angular-cdk-table-projected-columns

Repository files navigation

Angular Cdk Table Projected Columns

A quick example showing how to make a wrapper component around the CDK Table or MatTable. Instead of defining the highly verbose column definitions, this allows you to write slim components for the column definitions with options for the name, label, and an optional formatter callback to change the displayed data.

<app-table [dataSource]="data" [columns]="columns">
  <app-table-column name="id" label="ID"></app-table-column>
  <app-table-column name="title" label="Title"></app-table-column>
  <app-table-column name="author" label="Author"></app-table-column>
  <app-table-column
    name="price"
    label="Price"
    [formatter]="priceFormat"
  ></app-table-column>
</app-table>
columns = ['id', 'title', 'author', 'price'];

data = [
  ...
  {
    id: 2,
    title: 'The Lord of the Rings: The Two Towers',
    author: 'J.R.R. Tolkien',
    price: 16.99,
  },
  ....
];

priceFormat = (value: number) => {
  return this.currencyPipe.transform(value);
};

Take a look at the StackBlitz demo

About

A quick example showing how to make a wrapper component around the CDK Table or MatTable with projected columns.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published