Skip to content

Commit 3a194d1

Browse files
committed
update from review
1 parent 98e2e45 commit 3a194d1

File tree

3 files changed

+28
-33
lines changed

3 files changed

+28
-33
lines changed

src/cdk/table/table.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
getTableUnknownDataSourceError
5151
} from './table-errors';
5252

53+
/** Interface used to provide an outlet for rows to be inserted into. */
5354
export interface RowOutlet {
5455
viewContainer: ViewContainerRef;
5556
}
@@ -84,6 +85,7 @@ export class FooterRowOutlet implements RowOutlet {
8485
/**
8586
* The table template that can be used by the mat-table. Should not be used outside of the
8687
* material library.
88+
* @docs-private
8789
*/
8890
export const CDK_TABLE_TEMPLATE = `
8991
<ng-container headerRowOutlet></ng-container>
@@ -263,17 +265,10 @@ export class CdkTable<T> implements CollectionViewer, OnInit, AfterContentChecke
263265
// TODO(andrewseguin): Setup a listener for scrolling, emit the calculated view to viewChange
264266
this._dataDiffer = this._differs.find([]).create(this._trackByFn);
265267

266-
// If the table has a header row definition defined as part of its content, flag this as a
267-
// header row def change so that the content check will render the header row.
268-
if (this._headerRowDef) {
269-
this._headerRowDefChanged = true;
270-
}
271-
272-
// If the table has a footer row definition defined as part of its content, flag this as a
273-
// header row def change so that the content check will render the header row.
274-
if (this._footerRowDef) {
275-
this._footerRowDefChanged = true;
276-
}
268+
// If the table has header or footer row definitions defined as part of its content, mark that
269+
// there is a change so that the content check will render the row.
270+
this._headerRowDefChanged = !!this._headerRowDef;
271+
this._footerRowDefChanged = !!this._footerRowDef;
277272
}
278273

279274
ngAfterContentChecked() {
@@ -570,11 +565,11 @@ export class CdkTable<T> implements CollectionViewer, OnInit, AfterContentChecke
570565
// TODO(andrewseguin): enforce that one outlet was instantiated from createEmbeddedView
571566
outlet.viewContainer.createEmbeddedView(rowDef.template, context, index);
572567

573-
this._getCellTemplates(rowDef).forEach(cellTemplate => {
568+
for (let cellTemplate of this._getCellTemplates(rowDef)) {
574569
if (CdkCellOutlet.mostRecentCellOutlet) {
575570
CdkCellOutlet.mostRecentCellOutlet._viewContainer.createEmbeddedView(cellTemplate, context);
576571
}
577-
});
572+
}
578573

579574
this._changeDetectorRef.markForCheck();
580575
}
@@ -612,16 +607,16 @@ export class CdkTable<T> implements CollectionViewer, OnInit, AfterContentChecke
612607

613608
/** Adds native table sections (e.g. tbody) and moves the row outlets into them. */
614609
private _applyNativeTableSections() {
615-
const thead = document.createElement('thead');
616-
const tbody = document.createElement('tbody');
617-
const tfoot = document.createElement('tfoot');
618-
619-
this._elementRef.nativeElement.appendChild(thead);
620-
this._elementRef.nativeElement.appendChild(tbody);
621-
this._elementRef.nativeElement.appendChild(tfoot);
622-
623-
thead.appendChild(this._headerRowOutlet.elementRef.nativeElement);
624-
tbody.appendChild(this._rowOutlet.elementRef.nativeElement);
625-
tfoot.appendChild(this._footerRowOutlet.elementRef.nativeElement);
610+
const sections = [
611+
{tag: 'thead', outlet: this._headerRowOutlet},
612+
{tag: 'tbody', outlet: this._rowOutlet},
613+
{tag: 'tfoot', outlet: this._footerRowOutlet},
614+
];
615+
616+
for (const section of sections) {
617+
const element = document.createElement(section.tag);
618+
element.appendChild(section.outlet.elementRef.nativeElement);
619+
this._elementRef.nativeElement.appendChild(element);
620+
}
626621
}
627622
}
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<h3>Table with Footer</h3>
22

33
<mat-card class="demo-table-card">
4-
<mat-table [dataSource]="data" class="demo-footer-table">
4+
<table mat-table [dataSource]="data" class="demo-footer-table">
55
<ng-container matColumnDef="{{column}}" *ngFor="let column of columnsToDisplay">
6-
<mat-header-cell *matHeaderCellDef> {{column}} </mat-header-cell>
7-
<mat-cell *matCellDef="let element"> {{element[column]}} </mat-cell>
8-
<mat-footer-cell *matFooterCellDef> {{column}} Footer </mat-footer-cell>
6+
<th mat-header-cell *matHeaderCellDef> {{column}} </th>
7+
<td mat-cell *matCellDef="let element"> {{element[column]}} </td>
8+
<td mat-footer-cell *matFooterCellDef> {{column}} Footer </td>
99
</ng-container>
1010

11-
<mat-header-row *matHeaderRowDef="columnsToDisplay"></mat-header-row>
12-
<mat-row *matRowDef="let row; columns: columnsToDisplay;"></mat-row>
13-
<mat-footer-row *matFooterRowDef="columnsToDisplay">
14-
</mat-footer-row>
15-
</mat-table>
11+
<tr mat-header-row *matHeaderRowDef="columnsToDisplay"></tr>
12+
<tr mat-row *matRowDef="let row; columns: columnsToDisplay;"></tr>
13+
<tr mat-footer-row *matFooterRowDef="columnsToDisplay"></tr>
14+
</table>
1615
</mat-card>

src/demo-app/table/footer/footer-table.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
.demo-footer-table {
77
height: 500px;
8+
width: 100%;
89
overflow: auto;
910
}

0 commit comments

Comments
 (0)