@@ -20,6 +20,7 @@ import {
20
20
ViewEncapsulation ,
21
21
} from '@angular/core' ;
22
22
import { CdkCellDef , CdkColumnDef } from './cell' ;
23
+ import { CanStick , mixinHasStickyInput } from './can-stick' ;
23
24
24
25
/**
25
26
* 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 {
44
45
ngOnChanges ( changes : SimpleChanges ) : void {
45
46
// Create a new columns differ if one does not yet exist. Initialize it based on initial value
46
47
// of the columns property or an empty array if none is provided.
47
- const columns = changes [ 'columns' ] . currentValue || [ ] ;
48
48
if ( ! this . _columnsDiffer ) {
49
+ const columns = ( changes [ 'columns' ] && changes [ 'columns' ] . currentValue ) || [ ] ;
49
50
this . _columnsDiffer = this . _differs . find ( columns ) . create ( ) ;
50
51
this . _columnsDiffer . diff ( columns ) ;
51
52
}
@@ -60,44 +61,64 @@ export abstract class BaseRowDef implements OnChanges {
60
61
}
61
62
62
63
/** 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
+ }
64
73
}
65
74
75
+ // Boilerplate for applying mixins to CdkHeaderRowDef.
76
+ /** @docs -private */
77
+ export class CdkHeaderRowDefBase extends BaseRowDef { }
78
+ export const _CdkHeaderRowDefBase = mixinHasStickyInput ( CdkHeaderRowDefBase ) ;
79
+
66
80
/**
67
81
* Header row definition for the CDK table.
68
82
* Captures the header row's template and other header properties such as the columns to display.
69
83
*/
70
84
@Directive ( {
71
85
selector : '[cdkHeaderRowDef]' ,
72
- inputs : [ 'columns: cdkHeaderRowDef' ] ,
86
+ inputs : [ 'columns: cdkHeaderRowDef' , 'sticky: cdkHeaderRowDefSticky' ] ,
73
87
} )
74
- export class CdkHeaderRowDef extends BaseRowDef {
88
+ export class CdkHeaderRowDef extends _CdkHeaderRowDefBase implements CanStick , OnChanges {
75
89
constructor ( template : TemplateRef < any > , _differs : IterableDiffers ) {
76
90
super ( template , _differs ) ;
77
91
}
78
92
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 ) ;
82
97
}
83
98
}
84
99
100
+ // Boilerplate for applying mixins to CdkFooterRowDef.
101
+ /** @docs -private */
102
+ export class CdkFooterRowDefBase extends BaseRowDef { }
103
+ export const _CdkFooterRowDefBase = mixinHasStickyInput ( CdkFooterRowDefBase ) ;
104
+
85
105
/**
86
106
* Footer row definition for the CDK table.
87
107
* Captures the footer row's template and other footer properties such as the columns to display.
88
108
*/
89
109
@Directive ( {
90
110
selector : '[cdkFooterRowDef]' ,
91
- inputs : [ 'columns: cdkFooterRowDef' ] ,
111
+ inputs : [ 'columns: cdkFooterRowDef' , 'sticky: cdkFooterRowDefSticky' ] ,
92
112
} )
93
- export class CdkFooterRowDef extends BaseRowDef {
113
+ export class CdkFooterRowDef extends _CdkFooterRowDefBase implements CanStick , OnChanges {
94
114
constructor ( template : TemplateRef < any > , _differs : IterableDiffers ) {
95
115
super ( template , _differs ) ;
96
116
}
97
117
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 ) ;
101
122
}
102
123
}
103
124
@@ -124,11 +145,6 @@ export class CdkRowDef<T> extends BaseRowDef {
124
145
constructor ( template : TemplateRef < any > , _differs : IterableDiffers ) {
125
146
super ( template , _differs ) ;
126
147
}
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
- }
132
148
}
133
149
134
150
/** Context provided to the row cells when `multiTemplateDataRows` is false */
0 commit comments