Skip to content
This repository was archived by the owner on Jun 22, 2020. It is now read-only.

Commit 7ea65ce

Browse files
committed
fixup
1 parent 6f01bfd commit 7ea65ce

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

projects/table-builder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-ru/ng-table-builder",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"license": "MIT",
55
"bugs": {
66
"url": "https://github.com/Angular-RU/ng-table-builder/issues"

projects/table-builder/src/lib/table/directives/auto-height.directive.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { delay, takeUntil } from 'rxjs/operators';
1616
import { TABLE_GLOBAL_OPTIONS } from '../config/table-global-options';
1717
import { TableRow } from '../interfaces/table-builder.external';
1818
import { 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

2121
const DELAY: number = 100;
2222
const 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();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const SCROLLBAR_WIDTH: number = 12;
22
export const HEAD_TOP: string = '10px';
3+
export const BORDER_TOB_WITH_BOTTOM: number = 2;
34
export const MIN_PADDING_CONTEXT_ITEM: number = 25;
45
export const OVERLOAD_WIDTH_TABLE_HEAD_CELL: number = 90;

projects/table-builder/src/lib/tests/directives/auto-height.directive.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('[TEST]: auto height', () => {
7878
directive.recalculateTableSize();
7979
tick(100);
8080

81-
expect(style).toEqual(`display: block; height: calc(57px)`); // 45px + 12px (scrollbar height)
81+
expect(style).toEqual(`display: block; height: calc(59px)`); // 45px + 12px + 2px boarding (scrollbar height)
8282
}));
8383

8484
it('should be correct calculate auto height when columnHeight = 2000px', fakeAsync(() => {
@@ -87,7 +87,7 @@ describe('[TEST]: auto height', () => {
8787
directive.recalculateTableSize();
8888
tick(100);
8989

90-
expect(style).toEqual(`display: block; height: calc(980px - 0px - 0px - 12px)`);
90+
expect(style).toEqual(`display: block; height: calc(980px - 0px - 0px - 14px)`);
9191
}));
9292

9393
it('should be correct hide height not in viewport', () => {

src/app/samples/sample-first/sample-first.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export class SampleFirstComponent implements OnInit, OnDestroy {
1414
public width: string = '100%';
1515
public height: number;
1616
public rowHeight: string;
17-
public columnWidth: string;
1817
public dataSize: string = '100x20';
1918
public loading: boolean = false;
2019
public simple: TableRow[] = [];

0 commit comments

Comments
 (0)