77 * https://github.com/mikolalysenko/fenwick-tree
88 *
99 */
10- export class RowHeightCache {
10+ export class RowHeightCache < TRow > {
1111 /**
1212 * Tree Array stores the cumulative information of the row heights to perform efficient
1313 * range queries and updates. Currently the tree is initialized to the base row
@@ -24,12 +24,16 @@ export class RowHeightCache {
2424
2525 /**
2626 * Initialize the Fenwick tree with row Heights.
27- *
28- * @param rows The array of rows which contain the expanded status.
29- * @param rowHeight The row height.
30- * @param detailRowHeight The detail row height.
3127 */
32- initCache ( details : any ) : void {
28+ initCache ( details : {
29+ rows : TRow [ ] ;
30+ rowHeight : number | 'auto' | ( ( row : TRow ) => number ) ;
31+ detailRowHeight : number | ( ( row : TRow , index : number ) => number ) ;
32+ externalVirtual : boolean | undefined ;
33+ indexOffset : number ;
34+ rowCount : number ;
35+ rowExpansions : Set < TRow > ;
36+ } ) : void {
3337 const {
3438 rows,
3539 rowHeight,
@@ -42,7 +46,7 @@ export class RowHeightCache {
4246 const isFn = typeof rowHeight === 'function' ;
4347 const isDetailFn = typeof detailRowHeight === 'function' ;
4448
45- if ( ! isFn && isNaN ( rowHeight ) ) {
49+ if ( rowHeight === 'auto' || ( ! isFn && isNaN ( rowHeight ) ) ) {
4650 throw new Error ( `Row Height cache initialization failed. Please ensure that 'rowHeight' is a
4751 valid number or function value: (${ rowHeight } ) when 'scrollbarV' is enabled.` ) ;
4852 }
@@ -62,21 +66,13 @@ export class RowHeightCache {
6266
6367 for ( let i = 0 ; i < n ; ++ i ) {
6468 const row = rows [ i ] ;
65- let currentRowHeight = rowHeight ;
66- if ( isFn ) {
67- currentRowHeight = rowHeight ( row ) ;
68- }
69+ let currentRowHeight = isFn ? rowHeight ( row ) : rowHeight ;
6970
7071 // Add the detail row height to the already expanded rows.
7172 // This is useful for the table that goes through a filter or sort.
7273 const expanded = rowExpansions . has ( row ) ;
7374 if ( row && expanded ) {
74- if ( isDetailFn ) {
75- const index = indexOffset + i ;
76- currentRowHeight += detailRowHeight ( row , index ) ;
77- } else {
78- currentRowHeight += detailRowHeight ;
79- }
75+ currentRowHeight += isDetailFn ? detailRowHeight ( row , indexOffset + i ) : detailRowHeight ;
8076 }
8177
8278 this . update ( i , currentRowHeight ) ;
0 commit comments