@@ -20,6 +20,7 @@ import {
2020 ViewEncapsulation ,
2121} from '@angular/core' ;
2222import { CdkCellDef , CdkColumnDef } from './cell' ;
23+ import { CanStick , mixinHasStickyInput } from './can-stick' ;
2324
2425/**
2526 * The row template that can be used by the mat-table. Should not be used outside of the
@@ -44,8 +45,8 @@ export abstract class BaseRowDef implements OnChanges {
4445 ngOnChanges ( changes : SimpleChanges ) : void {
4546 // Create a new columns differ if one does not yet exist. Initialize it based on initial value
4647 // of the columns property or an empty array if none is provided.
47- const columns = changes [ 'columns' ] . currentValue || [ ] ;
4848 if ( ! this . _columnsDiffer ) {
49+ const columns = ( changes [ 'columns' ] && changes [ 'columns' ] . currentValue ) || [ ] ;
4950 this . _columnsDiffer = this . _differs . find ( columns ) . create ( ) ;
5051 this . _columnsDiffer . diff ( columns ) ;
5152 }
@@ -60,44 +61,64 @@ export abstract class BaseRowDef implements OnChanges {
6061 }
6162
6263 /** Gets this row def's relevant cell template from the provided column def. */
63- abstract extractCellTemplate ( column : CdkColumnDef ) : TemplateRef < any > ;
64+ extractCellTemplate ( column : CdkColumnDef ) : TemplateRef < any > {
65+ if ( this instanceof CdkHeaderRowDef ) {
66+ return column . headerCell . template ;
67+ } if ( this instanceof CdkFooterRowDef ) {
68+ return column . footerCell . template ;
69+ } else {
70+ return column . cell . template ;
71+ }
72+ }
6473}
6574
75+ // Boilerplate for applying mixins to CdkHeaderRowDef.
76+ /** @docs -private */
77+ export class CdkHeaderRowDefBase extends BaseRowDef { }
78+ export const _CdkHeaderRowDefBase = mixinHasStickyInput ( CdkHeaderRowDefBase ) ;
79+
6680/**
6781 * Header row definition for the CDK table.
6882 * Captures the header row's template and other header properties such as the columns to display.
6983 */
7084@Directive ( {
7185 selector : '[cdkHeaderRowDef]' ,
72- inputs : [ 'columns: cdkHeaderRowDef' ] ,
86+ inputs : [ 'columns: cdkHeaderRowDef' , 'sticky: cdkHeaderRowDefSticky' ] ,
7387} )
74- export class CdkHeaderRowDef extends BaseRowDef {
88+ export class CdkHeaderRowDef extends _CdkHeaderRowDefBase implements CanStick , OnChanges {
7589 constructor ( template : TemplateRef < any > , _differs : IterableDiffers ) {
7690 super ( template , _differs ) ;
7791 }
7892
79- /** Gets this row def's relevant cell template from the provided column def. */
80- extractCellTemplate ( column : CdkColumnDef ) : TemplateRef < any > {
81- return column . headerCell . template ;
93+ // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
94+ // Explicitly define it so that the method is called as part of the Angular lifecycle.
95+ ngOnChanges ( changes : SimpleChanges ) : void {
96+ super . ngOnChanges ( changes ) ;
8297 }
8398}
8499
100+ // Boilerplate for applying mixins to CdkFooterRowDef.
101+ /** @docs -private */
102+ export class CdkFooterRowDefBase extends BaseRowDef { }
103+ export const _CdkFooterRowDefBase = mixinHasStickyInput ( CdkFooterRowDefBase ) ;
104+
85105/**
86106 * Footer row definition for the CDK table.
87107 * Captures the footer row's template and other footer properties such as the columns to display.
88108 */
89109@Directive ( {
90110 selector : '[cdkFooterRowDef]' ,
91- inputs : [ 'columns: cdkFooterRowDef' ] ,
111+ inputs : [ 'columns: cdkFooterRowDef' , 'sticky: cdkFooterRowDefSticky' ] ,
92112} )
93- export class CdkFooterRowDef extends BaseRowDef {
113+ export class CdkFooterRowDef extends _CdkFooterRowDefBase implements CanStick , OnChanges {
94114 constructor ( template : TemplateRef < any > , _differs : IterableDiffers ) {
95115 super ( template , _differs ) ;
96116 }
97117
98- /** Gets this row def's relevant cell template from the provided column def. */
99- extractCellTemplate ( column : CdkColumnDef ) : TemplateRef < any > {
100- return column . footerCell . template ;
118+ // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance.
119+ // Explicitly define it so that the method is called as part of the Angular lifecycle.
120+ ngOnChanges ( changes : SimpleChanges ) : void {
121+ super . ngOnChanges ( changes ) ;
101122 }
102123}
103124
@@ -124,11 +145,6 @@ export class CdkRowDef<T> extends BaseRowDef {
124145 constructor ( template : TemplateRef < any > , _differs : IterableDiffers ) {
125146 super ( template , _differs ) ;
126147 }
127-
128- /** Gets this row def's relevant cell template from the provided column def. */
129- extractCellTemplate ( column : CdkColumnDef ) : TemplateRef < any > {
130- return column . cell . template ;
131- }
132148}
133149
134150/** Context provided to the row cells when `multiTemplateDataRows` is false */
0 commit comments