@@ -2,6 +2,8 @@ import { action, computed, makeAutoObservable, observable } from "mobx";
22import { createRef } from "react" ;
33import { PaginationController } from "../services/PaginationController" ;
44
5+ export const VIRTUAL_SCROLLING_OFFSET = 30 ;
6+
57export class GridSizeStore {
68 gridContainerRef = createRef < HTMLDivElement > ( ) ;
79 gridBodyRef = createRef < HTMLDivElement > ( ) ;
@@ -29,7 +31,7 @@ export class GridSizeStore {
2931 setGridWidth : action ,
3032
3133 gridBodyHeight : observable ,
32- setGridBodyHeight : action ,
34+ lockGridBodyHeight : action ,
3335
3436 columnSizes : observable ,
3537 updateColumnSizes : action ,
@@ -38,10 +40,6 @@ export class GridSizeStore {
3840 } ) ;
3941 }
4042
41- get hasMoreItems ( ) : boolean {
42- return this . paging . hasMoreItems ;
43- }
44-
4543 get hasVirtualScrolling ( ) : boolean {
4644 return this . paging . pagination === "virtualScrolling" ;
4745 }
@@ -64,11 +62,31 @@ export class GridSizeStore {
6462 this . gridWidth = size ;
6563 }
6664
67- setGridBodyHeight ( size : number ) : void {
68- this . gridBodyHeight = size ;
69- }
70-
7165 updateColumnSizes ( sizes : number [ ] ) : void {
7266 this . columnSizes = sizes ;
7367 }
68+
69+ lockGridBodyHeight ( ) : void {
70+ if ( ! this . hasVirtualScrolling || ! this . paging . hasMoreItems ) {
71+ return ;
72+ }
73+ const gridBody = this . gridBodyRef . current ;
74+ if ( ! gridBody || this . gridBodyHeight !== undefined ) {
75+ return ;
76+ }
77+
78+ this . gridBodyHeight = gridBody . clientHeight - VIRTUAL_SCROLLING_OFFSET ;
79+ }
7480}
81+
82+ /**
83+ * const lockGridBodyHeight = useCallback((): void => {
84+ * if (isVisible && hasVirtualScrolling && hasMoreItems && gridBodyHeight === undefined && gridBody) {
85+ * gridSizeStore.setGridBodyHeight(gridBody.clientHeight - offsetBottom);
86+ * }
87+ * }, [isVisible, hasVirtualScrolling, hasMoreItems, gridBodyHeight, gridBody, gridSizeStore]);
88+ *
89+ * useLayoutEffect(() => {
90+ * setTimeout(() => lockGridBodyHeight(), 100);
91+ * }, [lockGridBodyHeight]);
92+ */
0 commit comments