@@ -64,6 +64,7 @@ import type { Node } from '../facet/layout/node';
6464import { RootInteraction } from '../interaction/root' ;
6565import { getTheme } from '../theme' ;
6666import { HdAdapter } from '../ui/hd-adapter' ;
67+ import { StickyHeaderController } from '../ui/sticky-header' ;
6768import { BaseTooltip } from '../ui/tooltip' ;
6869import { getOffscreenCanvas , removeOffscreenCanvas } from '../utils/canvas' ;
6970import { clearValueRangeState } from '../utils/condition/state-controller' ;
@@ -98,6 +99,8 @@ export abstract class SpreadSheet extends EE {
9899
99100 public hdAdapter : HdAdapter ;
100101
102+ public stickyHeaderController : StickyHeaderController | null = null ;
103+
101104 /**
102105 * 表格是否已销毁
103106 */
@@ -152,6 +155,7 @@ export abstract class SpreadSheet extends EE {
152155 this . registerIcons ( ) ;
153156 this . setOverscrollBehavior ( ) ;
154157 this . mountSheetInstance ( ) ;
158+ this . initStickyHeader ( ) ;
155159 }
156160
157161 protected setupDataConfig ( dataCfg : S2DataConfig ) {
@@ -244,6 +248,24 @@ export abstract class SpreadSheet extends EE {
244248 }
245249 }
246250
251+ /**
252+ * 初始化表头吸顶控制器 (延迟到首次渲染完成后)
253+ */
254+ private initStickyHeader ( ) {
255+ if ( ! this . options . interaction ?. stickyHeader ) {
256+ return ;
257+ }
258+
259+ // 吸顶控制器依赖 facet.cornerBBox, 需要在首次渲染完成后才能初始化
260+ const onFirstRender = ( ) => {
261+ this . off ( S2Event . LAYOUT_AFTER_RENDER , onFirstRender ) ;
262+ this . stickyHeaderController ?. destroy ( ) ;
263+ this . stickyHeaderController = new StickyHeaderController ( this ) ;
264+ } ;
265+
266+ this . on ( S2Event . LAYOUT_AFTER_RENDER , onFirstRender ) ;
267+ }
268+
247269 protected initInteraction ( ) {
248270 this . interaction ?. destroy ?.( ) ;
249271 this . interaction = new RootInteraction ( this ) ;
@@ -410,6 +432,24 @@ export abstract class SpreadSheet extends EE {
410432
411433 this . resetHiddenColumnsDetailInfoIfNeeded ( ) ;
412434 this . registerIcons ( ) ;
435+ this . syncStickyHeader ( ) ;
436+ }
437+
438+ /**
439+ * 同步吸顶控制器状态:options 更新后如果 stickyHeader 配置变更则销毁/重建
440+ */
441+ private syncStickyHeader ( ) {
442+ const enabled = ! ! this . options . interaction ?. stickyHeader ;
443+
444+ // 先销毁旧控制器(无论是关闭还是选项内容变更都需要重建)
445+ if ( this . stickyHeaderController ) {
446+ this . stickyHeaderController . destroy ( ) ;
447+ this . stickyHeaderController = null ;
448+ }
449+
450+ if ( enabled ) {
451+ this . initStickyHeader ( ) ;
452+ }
413453 }
414454
415455 /**
@@ -528,6 +568,8 @@ export abstract class SpreadSheet extends EE {
528568 this . destroyed = true ;
529569 this . restoreOverscrollBehavior ( ) ;
530570 this . emit ( S2Event . LAYOUT_DESTROY ) ;
571+ this . stickyHeaderController ?. destroy ( ) ;
572+ this . stickyHeaderController = null ;
531573 this . facet ?. destroy ( ) ;
532574 this . hdAdapter ?. destroy ( ) ;
533575 this . interaction ?. destroy ( ) ;
0 commit comments