Skip to content

Commit c67e7b2

Browse files
fix: correctly calculate ghost-loader height if rowHeight = 'auto'
1 parent f389894 commit c67e7b2

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

projects/ngx-datatable/src/lib/components/body/body.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export class DataTableBodyComponent<TRow extends Row = any> implements OnInit, O
352352
this.recalcLayout();
353353
}
354354

355-
get bodyHeight() {
355+
get bodyHeight(): string {
356356
return this._bodyHeight;
357357
}
358358

projects/ngx-datatable/src/lib/components/body/ghost-loader/ghost-loader.component.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
<div class="ghost-loader ghost-cell-container" [style.height.px]="ghostBodyHeight">
2-
@for (item of [].constructor(pageSize); track item) {
3-
<div class="ghost-element" [style.height.px]="rowHeight" [class.datatable-body-row]="cellMode">
4-
@for (col of columns; track col) {
5-
<div class="ghost-cell" [class.datatable-body-cell]="cellMode" [style.width.px]="col.width">
1+
<div class="ghost-loader ghost-cell-container" [style.height]="ghostBodyHeight()">
2+
@for (item of [].constructor(pageSize()); track item) {
3+
<div
4+
class="ghost-element"
5+
[style.height]="rowHeightComputed()"
6+
[class.datatable-body-row]="cellMode()"
7+
>
8+
@for (col of columns(); track col) {
9+
<div
10+
class="ghost-cell"
11+
[class.datatable-body-cell]="cellMode()"
12+
[style.width.px]="col.width"
13+
>
614
@if (!col.ghostCellTemplate) {
715
<div class="line ghost-cell-strip"></div>
816
} @else {

projects/ngx-datatable/src/lib/components/body/ghost-loader/ghost-loader.component.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
booleanAttribute,
44
ChangeDetectionStrategy,
55
Component,
6-
Input,
7-
numberAttribute
6+
numberAttribute,
7+
input
88
} from '@angular/core';
99

1010
import { TableColumnInternal } from '../../../types/internal.types';
@@ -17,9 +17,16 @@ import { TableColumnInternal } from '../../../types/internal.types';
1717
imports: [NgTemplateOutlet]
1818
})
1919
export class DataTableGhostLoaderComponent {
20-
@Input() columns!: TableColumnInternal[];
21-
@Input({ transform: numberAttribute }) pageSize!: number;
22-
@Input() rowHeight!: number | 'auto' | ((row?: any) => number);
23-
@Input({ transform: numberAttribute }) ghostBodyHeight?: number;
24-
@Input({ transform: booleanAttribute }) cellMode = false;
20+
readonly columns = input.required<TableColumnInternal[]>();
21+
readonly pageSize = input.required<number, unknown>({ transform: numberAttribute });
22+
readonly rowHeight = input.required<number | 'auto' | ((row?: any) => number)>();
23+
readonly ghostBodyHeight = input<string>();
24+
readonly cellMode = input(false, { transform: booleanAttribute });
25+
26+
protected readonly rowHeightComputed = () => {
27+
if (typeof this.rowHeight() === 'function') {
28+
return this.rowHeight() + 'px';
29+
}
30+
return this.rowHeight() === 'auto' ? 100 / this.pageSize() + '%' : this.rowHeight() + 'px';
31+
};
2532
}

0 commit comments

Comments
 (0)