@@ -465,7 +465,9 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
465
465
}
466
466
467
467
// Render updates if the list of columns have been changed for the header, row, or footer defs.
468
- this . _renderUpdatedColumns ( ) ;
468
+ const columnsChanged = this . _renderUpdatedColumns ( ) ;
469
+ const stickyColumnStyleUpdateNeeded =
470
+ columnsChanged || this . _headerRowDefChanged || this . _footerRowDefChanged ;
469
471
470
472
// If the header row definition has been changed, trigger a render to the header row.
471
473
if ( this . _headerRowDefChanged ) {
@@ -483,6 +485,10 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
483
485
// connection has already been made.
484
486
if ( this . dataSource && this . _rowDefs . length > 0 && ! this . _renderChangeSubscription ) {
485
487
this . _observeRenderChanges ( ) ;
488
+ } else if ( stickyColumnStyleUpdateNeeded ) {
489
+ // In the above case, _observeRenderChanges will result in updateStickyColumnStyles being
490
+ // called when it row data arrives. Otherwise, we need to call it proactively.
491
+ this . updateStickyColumnStyles ( ) ;
486
492
}
487
493
488
494
this . _checkStickyStates ( ) ;
@@ -790,22 +796,27 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
790
796
* whether the sticky states have changed for the header or footer. If there is a diff, then
791
797
* re-render that section.
792
798
*/
793
- private _renderUpdatedColumns ( ) {
799
+ private _renderUpdatedColumns ( ) : boolean {
794
800
const columnsDiffReducer = ( acc : boolean , def : BaseRowDef ) => acc || ! ! def . getColumnsDiff ( ) ;
795
801
796
802
// Force re-render data rows if the list of column definitions have changed.
797
- if ( this . _rowDefs . reduce ( columnsDiffReducer , false ) ) {
803
+ const dataColumnsChanged = this . _rowDefs . reduce ( columnsDiffReducer , false ) ;
804
+ if ( dataColumnsChanged ) {
798
805
this . _forceRenderDataRows ( ) ;
799
806
}
800
807
801
- // Force re-render header/footer rows if the list of column definitions have changed..
802
- if ( this . _headerRowDefs . reduce ( columnsDiffReducer , false ) ) {
808
+ // Force re-render header/footer rows if the list of column definitions have changed.
809
+ const headerColumnsChanged = this . _headerRowDefs . reduce ( columnsDiffReducer , false ) ;
810
+ if ( headerColumnsChanged ) {
803
811
this . _forceRenderHeaderRows ( ) ;
804
812
}
805
813
806
- if ( this . _footerRowDefs . reduce ( columnsDiffReducer , false ) ) {
814
+ const footerColumnsChanged = this . _footerRowDefs . reduce ( columnsDiffReducer , false ) ;
815
+ if ( footerColumnsChanged ) {
807
816
this . _forceRenderFooterRows ( ) ;
808
817
}
818
+
819
+ return dataColumnsChanged || headerColumnsChanged || footerColumnsChanged ;
809
820
}
810
821
811
822
/**
@@ -875,7 +886,6 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
875
886
876
887
this . _headerRowDefs . forEach ( ( def , i ) => this . _renderRow ( this . _headerRowOutlet , def , i ) ) ;
877
888
this . updateStickyHeaderRowStyles ( ) ;
878
- this . updateStickyColumnStyles ( ) ;
879
889
}
880
890
/**
881
891
* Clears any existing content in the footer row outlet and creates a new embedded view
@@ -889,7 +899,6 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
889
899
890
900
this . _footerRowDefs . forEach ( ( def , i ) => this . _renderRow ( this . _footerRowOutlet , def , i ) ) ;
891
901
this . updateStickyFooterRowStyles ( ) ;
892
- this . updateStickyColumnStyles ( ) ;
893
902
}
894
903
895
904
/** Adds the sticky column styles for the rows according to the columns' stick states. */
@@ -1049,7 +1058,6 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
1049
1058
this . _dataDiffer . diff ( [ ] ) ;
1050
1059
this . _rowOutlet . viewContainer . clear ( ) ;
1051
1060
this . renderRows ( ) ;
1052
- this . updateStickyColumnStyles ( ) ;
1053
1061
}
1054
1062
1055
1063
/**
0 commit comments