Skip to content

Commit 15e1641

Browse files
committed
checkin
1 parent ac3e21a commit 15e1641

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/cdk/table/table.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ export class CdkTable<T> implements CollectionViewer {
193193
this._columnDefinitionsByName.set(columnDef.name, columnDef);
194194
});
195195

196+
this._columnDefinitions.changes.subscribe(() => {
197+
console.log('Column def change');
198+
});
199+
196200
// Re-render the rows if any of their columns change.
197201
// TODO(andrewseguin): Determine how to only re-render the rows that have their columns changed.
198202
const columnChangeEvents = this._rowDefinitions.map(rowDef => rowDef.columnsChange);
@@ -206,6 +210,7 @@ export class CdkTable<T> implements CollectionViewer {
206210

207211
// Re-render the header row if the columns change
208212
takeUntil.call(this._headerDefinition.columnsChange, this._onDestroy).subscribe(() => {
213+
console.log('Header columns changed');
209214
this._headerRowPlaceholder.viewContainer.clear();
210215
this._renderHeaderRow();
211216
});

src/demo-app/table/table-demo.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,24 @@
2525
<md-checkbox (change)="toggleHighlight('even', $event.checked)">Even Rows</md-checkbox>
2626
<md-checkbox (change)="toggleHighlight('odd', $event.checked)">Odd Rows</md-checkbox>
2727
</div>
28+
29+
<div>
30+
<button md-raised-button (click)="addDynamicColumnDef()">Add Dynamic Column Def</button>
31+
</div>
2832
</div>
2933

34+
<h3>CdkTable With Dynamic Column Def</h3>
35+
36+
<cdk-table [dataSource]="dataSource">
37+
<ng-container cdkColumnDef="column.id" *ngFor="let column of dynamicColumns">
38+
<cdk-header-cell *cdkHeaderCellDef> {{column.headerText}} </cdk-header-cell>
39+
<cdk-cell *cdkCellDef="let row"> {{row[column.property]}} </cdk-cell>
40+
</ng-container>
41+
42+
<cdk-header-row *cdkHeaderRowDef="dynamicColumnIds"></cdk-header-row>
43+
<cdk-row *cdkRowDef="let row; columns: dynamicColumnIds;"></cdk-row>
44+
</cdk-table>
45+
3046
<h3>CdkTable Example</h3>
3147

3248
<cdk-table #table mdSort

src/demo-app/table/table-demo.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export class TableDemo {
2121
changeReferences = false;
2222
highlights = new Set<string>();
2323

24+
dynamicColumns: any[] = [];
25+
dynamicColumnIds: string[] = [];
26+
2427
@ViewChild(MdPaginator) _paginator: MdPaginator;
2528

2629
@ViewChild(MdSort) sort: MdSort;
@@ -31,6 +34,18 @@ export class TableDemo {
3134
this.connect();
3235
}
3336

37+
addDynamicColumnDef() {
38+
const properties = ['userId', 'userName', 'progress', 'color'];
39+
const nextProperty = properties[this.dynamicColumns.length];
40+
this.dynamicColumns.push({
41+
id: nextProperty,
42+
property: nextProperty,
43+
headerText: nextProperty
44+
});
45+
46+
this.dynamicColumnIds.push(nextProperty);
47+
}
48+
3449
connect() {
3550
this.displayedColumns = ['userId', 'userName', 'progress', 'color'];
3651
this.dataSource = new PersonDataSource(this._peopleDatabase,

0 commit comments

Comments
 (0)