@@ -20,6 +20,8 @@ import {
2020 ViewEncapsulation ,
2121} from '@angular/core' ;
2222import { CdkCellDef , CdkColumnDef } from './cell' ;
23+ import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
24+ import { HasStickyState , mixinHasStickyInput } from './has-sticky-state' ;
2325
2426/**
2527 * 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 {
4446 ngOnChanges ( changes : SimpleChanges ) : void {
4547 // Create a new columns differ if one does not yet exist. Initialize it based on initial value
4648 // of the columns property or an empty array if none is provided.
47- const columns = changes [ 'columns' ] . currentValue || [ ] ;
4849 if ( ! this . _columnsDiffer ) {
50+ const columns = ( changes [ 'columns' ] && changes [ 'columns' ] . currentValue ) || [ ] ;
4951 this . _columnsDiffer = this . _differs . find ( columns ) . create ( ) ;
5052 this . _columnsDiffer . diff ( columns ) ;
5153 }
@@ -60,44 +62,68 @@ export abstract class BaseRowDef implements OnChanges {
6062 }
6163
6264 /** 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+ }
6474}
6575
76+ // Boilerplate for applying mixins to CdkHeaderRowDef.
77+ /** @docs -private */
78+ export class CdkHeaderRowDefBase extends BaseRowDef { }
79+ export const _CdkHeaderRowDefBase = mixinHasStickyInput ( CdkHeaderRowDefBase ) ;
80+
6681/**
6782 * Header row definition for the CDK table.
6883 * Captures the header row's template and other header properties such as the columns to display.
6984 */
7085@Directive ( {
7186 selector : '[cdkHeaderRowDef]' ,
72- inputs : [ 'columns: cdkHeaderRowDef' ] ,
87+ inputs : [ 'columns: cdkHeaderRowDef' , 'sticky: cdkHeaderRowDefSticky' ] ,
7388} )
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 ;
7794 }
95+ get sticky ( ) : boolean { return this . _sticky ; }
96+ _sticky : boolean ;
7897
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 ) ;
82100 }
83101}
84102
103+ // Boilerplate for applying mixins to CdkFooterRowDef.
104+ /** @docs -private */
105+ export class CdkFooterRowDefBase extends BaseRowDef { }
106+ export const _CdkFooterRowDefBase = mixinHasStickyInput ( CdkFooterRowDefBase ) ;
107+
85108/**
86109 * Footer row definition for the CDK table.
87110 * Captures the footer row's template and other footer properties such as the columns to display.
88111 */
89112@Directive ( {
90113 selector : '[cdkFooterRowDef]' ,
91- inputs : [ 'columns: cdkFooterRowDef' ] ,
114+ inputs : [ 'columns: cdkFooterRowDef' , 'sticky: cdkFooterRowDefSticky' ] ,
92115} )
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 ;
96121 }
122+ get sticky ( ) : boolean { return this . _sticky ; }
123+ _sticky : boolean ;
97124
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 ) ;
101127 }
102128}
103129
@@ -124,11 +150,6 @@ export class CdkRowDef<T> extends BaseRowDef {
124150 constructor ( template : TemplateRef < any > , _differs : IterableDiffers ) {
125151 super ( template , _differs ) ;
126152 }
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- }
132153}
133154
134155/** Context provided to the row cells when `multiTemplateDataRows` is false */
0 commit comments