@@ -50,6 +50,7 @@ import {
50
50
getTableUnknownDataSourceError
51
51
} from './table-errors' ;
52
52
53
+ /** Interface used to provide an outlet for rows to be inserted into. */
53
54
export interface RowOutlet {
54
55
viewContainer : ViewContainerRef ;
55
56
}
@@ -84,6 +85,7 @@ export class FooterRowOutlet implements RowOutlet {
84
85
/**
85
86
* The table template that can be used by the mat-table. Should not be used outside of the
86
87
* material library.
88
+ * @docs -private
87
89
*/
88
90
export const CDK_TABLE_TEMPLATE = `
89
91
<ng-container headerRowOutlet></ng-container>
@@ -263,17 +265,10 @@ export class CdkTable<T> implements CollectionViewer, OnInit, AfterContentChecke
263
265
// TODO(andrewseguin): Setup a listener for scrolling, emit the calculated view to viewChange
264
266
this . _dataDiffer = this . _differs . find ( [ ] ) . create ( this . _trackByFn ) ;
265
267
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 ;
277
272
}
278
273
279
274
ngAfterContentChecked ( ) {
@@ -570,11 +565,11 @@ export class CdkTable<T> implements CollectionViewer, OnInit, AfterContentChecke
570
565
// TODO(andrewseguin): enforce that one outlet was instantiated from createEmbeddedView
571
566
outlet . viewContainer . createEmbeddedView ( rowDef . template , context , index ) ;
572
567
573
- this . _getCellTemplates ( rowDef ) . forEach ( cellTemplate => {
568
+ for ( let cellTemplate of this . _getCellTemplates ( rowDef ) ) {
574
569
if ( CdkCellOutlet . mostRecentCellOutlet ) {
575
570
CdkCellOutlet . mostRecentCellOutlet . _viewContainer . createEmbeddedView ( cellTemplate , context ) ;
576
571
}
577
- } ) ;
572
+ }
578
573
579
574
this . _changeDetectorRef . markForCheck ( ) ;
580
575
}
@@ -612,16 +607,16 @@ export class CdkTable<T> implements CollectionViewer, OnInit, AfterContentChecke
612
607
613
608
/** Adds native table sections (e.g. tbody) and moves the row outlets into them. */
614
609
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
+ }
626
621
}
627
622
}
0 commit comments