[Table] Add example with dynamic columns
See original GitHub issueBug, feature request, or proposal:
Proposal
What is the expected behavior?
It’d be nice to have example(s) on how to use md-table
with dynamic columns.
What is the current behavior?
Currently all the examples are with hard coded columns, like this:
<!-- ID Column -->
<ng-container cdkColumnDef="userId">
<md-header-cell *cdkHeaderCellDef md-sort-header> ID </md-header-cell>
<md-cell *cdkCellDef="let row"> {{row.id}} </md-cell>
</ng-container>
<!-- Progress Column -->
<ng-container cdkColumnDef="progress">
<md-header-cell *cdkHeaderCellDef md-sort-header> Progress </md-header-cell>
<md-cell *cdkCellDef="let row"> {{row.progress}}% </md-cell>
</ng-container>
Issue Analytics
- State:
- Created 6 years ago
- Reactions:49
- Comments:59 (11 by maintainers)
Top Results From Across the Web
CREATE TABLE with Dynamic Column - sql - Stack Overflow
Another option is to create a table with NULL columns. To do this in SQL, you can do the following: CREATE TABLE tblPerson...
Read more >Dynamic Columns - MariaDB Knowledge Base
Dynamic columns allow one to store different sets of columns for each row in a table. It works by storing a set of...
Read more >Table Records with dynamic columns | OutSystems
Hi guys, I need to have table records where the columns are dynamic and I have no more ideas on how to do...
Read more >How to Create Dynamic Tables from Editable Columns in ...
Call the function on component mount to get the inventory data to populate the table. To dynamically create the rows, iterate through the...
Read more >Table dynamically changing the columns displayed - StackBlitz
Table dynamically changing the columns displayed. ... Add column </button>. <button mat-raised-button (click) ... <tr mat-row *matRowDef="let row; columns:.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For those interested, here was my approach
https://plnkr.co/edit/UntMipJO7lQVFCCSq3sZ?p=preview
EDIT: Here is a (hopefully) evergreen stackblitz with the exact same approach
https://stackblitz.com/edit/material2-beta11-vmwjpe
This should work:
<div *ngFor="let displayedColumn of displayedColumns; let columnIndex = index"> <ng-container *ngIf="displayedColumn !='actions'" matColumnDef="{{displayedColumn}}"> <mat-header-cell *matHeaderCellDef mat-sort-header>{{displayedColumn}}</mat-header-cell> <mat-cell *matCellDef="let element "> {{element[displayedColumn]}}</mat-cell> </ng-container> </div> <ng-container matColumnDef="actions"> <mat-header-cell *matHeaderCellDef >Actions</mat-header-cell> <mat-cell *matCellDef="let element "> <button mat-raised-button> Edit </button> </mat-cell> </ng-container>