@@ -16,7 +16,7 @@ import { delay, takeUntil } from 'rxjs/operators';
1616import { TABLE_GLOBAL_OPTIONS } from '../config/table-global-options' ;
1717import { TableRow } from '../interfaces/table-builder.external' ;
1818import { Any , BoxView , DynamicHeightOptions } from '../interfaces/table-builder.internal' ;
19- import { HEAD_TOP , SCROLLBAR_WIDTH } from '../symbols' ;
19+ import { BORDER_TOB_WITH_BOTTOM , HEAD_TOP , SCROLLBAR_WIDTH } from '../symbols' ;
2020
2121const DELAY : number = 100 ;
2222const MIN_RESIZE_DELAY : number = 200 ;
@@ -57,7 +57,7 @@ export class AutoHeightDirective implements OnInit, OnChanges, OnDestroy {
5757 if ( this . useOnlyAutoViewPort && this . columnHeight > this . parentOffsetHeight ) {
5858 height = this . getHeightByViewPort ( { paddingTop, paddingBottom } ) ;
5959 } else if ( this . parentOffsetHeight > this . columnHeight ) {
60- height = this . getDefaultHeight ( ) ;
60+ height = this . getDefaultHeight ( this . parentOffsetHeight ) ;
6161 } else if ( this . isNotEmptyParentHeight ) {
6262 height = this . getHeightByParent ( { paddingTop, paddingBottom } ) ;
6363 } else {
@@ -73,7 +73,7 @@ export class AutoHeightDirective implements OnInit, OnChanges, OnDestroy {
7373 }
7474
7575 private get parentOffsetHeight ( ) : number {
76- return this . rootCurrentElement . clientHeight || this . minHeight ;
76+ return ( this . rootCurrentElement . clientHeight || this . minHeight ) - this . scrollbarHeight - BORDER_TOB_WITH_BOTTOM ;
7777 }
7878
7979 private get currentElement ( ) : HTMLDivElement {
@@ -93,9 +93,11 @@ export class AutoHeightDirective implements OnInit, OnChanges, OnDestroy {
9393 }
9494
9595 private get scrollbarHeight ( ) : number {
96- return this . sourceRef . length === 1
97- ? SCROLLBAR_WIDTH
98- : this . tableViewport . offsetHeight - this . tableViewport . clientHeight || 0 ;
96+ const scrollHeight : number =
97+ this . sourceRef . length === 1
98+ ? SCROLLBAR_WIDTH
99+ : this . tableViewport . offsetHeight - this . tableViewport . clientHeight || 0 ;
100+ return scrollHeight + BORDER_TOB_WITH_BOTTOM ;
99101 }
100102
101103 private get headerHeight ( ) : number {
@@ -171,8 +173,14 @@ export class AutoHeightDirective implements OnInit, OnChanges, OnDestroy {
171173 }
172174 }
173175
174- private getDefaultHeight ( ) : string {
175- return `calc(${ this . columnHeight + this . scrollbarHeight + this . headerHeight + this . footerHeight } px)` ;
176+ private getDefaultHeight ( parentHeight ?: number ) : string {
177+ let height : number = this . columnHeight + this . scrollbarHeight + this . headerHeight + this . footerHeight ;
178+
179+ if ( parentHeight ) {
180+ height = height > parentHeight ? parentHeight : height ;
181+ }
182+
183+ return `calc(${ height } px)` ;
176184 }
177185
178186 private getHeightByParent ( { paddingTop, paddingBottom } : BoxView ) : string {
@@ -182,7 +190,6 @@ export class AutoHeightDirective implements OnInit, OnChanges, OnDestroy {
182190
183191 private getHeightByViewPort ( { paddingTop, paddingBottom } : BoxView ) : string {
184192 const viewportHeight : number = this . autoViewHeight - parseInt ( HEAD_TOP ) ;
185-
186193 return this . columnHeight > viewportHeight
187194 ? `calc(${ viewportHeight } px - ${ paddingTop } - ${ paddingBottom } - ${ this . scrollbarHeight } px)`
188195 : this . getDefaultHeight ( ) ;
0 commit comments