@@ -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. */
5354export 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 */
8890export 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}
0 commit comments