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