Skip to content

Commit dee5ee1

Browse files
fix: add default block padding to ghost elements
show border on each ghost element in case of cellMode is off and also hide outer ghost overlay if cellMode is on to avoid duplication.
1 parent f389894 commit dee5ee1

File tree

7 files changed

+38
-14
lines changed

7 files changed

+38
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { DataTableSummaryRowComponent } from './summary/summary-row.component';
5353
</div>
5454
</div>
5555
}
56-
@if (ghostLoadingIndicator && (!rowCount || !virtualization || !scrollbarV)) {
56+
@if (ghostLoadingIndicator && !rows.length && (!rowCount || !virtualization || !scrollbarV)) {
5757
<ghost-loader
5858
class="ghost-overlay"
5959
[columns]="columns"
@@ -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.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
inset-block-start: 20px;
3434

3535
.ghost-cell {
36+
padding-block: 0.9rem;
3637
padding-inline: 1.2rem;
3738
}
3839
}

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

Lines changed: 15 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,17 @@ 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+
const rowHeight = this.rowHeight();
28+
if (typeof rowHeight === 'function') {
29+
return rowHeight() + 'px';
30+
}
31+
return rowHeight === 'auto' ? 'auto' : rowHeight + 'px';
32+
};
2533
}

projects/ngx-datatable/src/lib/themes/_ghost.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ $datatable-ghost-cell-strip-background-image: linear-gradient(
99
) !default;
1010
$datatable-ghost-cell-strip-radius: 4px !default;
1111
$datatble-ghost-cell-animation-duration: 10s;
12+
$datatable-ghost-row-border-color: #d9d8d9 !default;
1213

1314
.ghost-cell-container {
1415
background: $datatable-ghost-cell-container-background;
@@ -20,3 +21,7 @@ $datatble-ghost-cell-animation-duration: 10s;
2021
border-radius: $datatable-ghost-cell-strip-radius;
2122
animation-duration: $datatble-ghost-cell-animation-duration;
2223
}
24+
25+
.ghost-element {
26+
border-block-end: 1px solid $datatable-ghost-row-border-color;
27+
}

projects/ngx-datatable/src/lib/themes/bootstrap.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $datatable-ghost-cell-strip-background-image: linear-gradient(
1010
) !default;
1111
$datatable-ghost-cell-strip-radius: 0 !default;
1212
$datatble-ghost-cell-animation-duration: 10s;
13+
$datatable-ghost-row-border-color: #d1d4d7 !default;
1314

1415
@import './ghost';
1516
@import './rows';

projects/ngx-datatable/src/lib/themes/material.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ $datatable-ghost-cell-strip-background-image: linear-gradient(
8080
) !default;
8181
$datatable-ghost-cell-strip-radius: 0 !default;
8282
$datatble-ghost-cell-animation-duration: 10s;
83+
$datatable-ghost-row-border-color: $datatable-body-row-border-bottom-color !default;
8384

8485
@import './ghost';
8586
@import './rows';

0 commit comments

Comments
 (0)