Skip to content

Commit ca6ac73

Browse files
committed
chore: add loader for grid component
1 parent 9aba7f4 commit ca6ac73

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

examples-standalone/kendoangular-landing-page/src/app/components/dynamic-grid/dynamic-grid.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
[pageSize]="state.take"
1111
[columnMenu]="menuSettings"
1212
[sortable]="true"
13+
[loading]="loading"
1314
(dataStateChange)="dataStateChange($event)"
1415
>
1516
<ng-template kendoGridToolbarTemplate>

examples-standalone/kendoangular-landing-page/src/app/components/dynamic-grid/dynamic-grid.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ import { MultiCheckboxFilterComponent } from './multi-checkbox-filter/multi-chec
3939
templateUrl: './dynamic-grid.component.html',
4040
styleUrl: './dynamic-grid.component.css',
4141
})
42-
export class DynamicGridComponent {
42+
export class DynamicGridComponent implements OnInit, OnDestroy {
4343
public gridView!: GridDataResult;
4444
public refreshInterval: number = 100;
4545
public currentGridDataSize: { text: string; value: number } = { text: '100', value: 100 };
4646
public positivePriceChangeIcon: SVGIcon = caretAltUpIcon;
4747
public negativePriceChangeIcon: SVGIcon = caretAltDownIcon;
48+
public loading: boolean = false;
4849

4950
private dataSubscription!: Subscription;
5051

@@ -73,6 +74,10 @@ export class DynamicGridComponent {
7374
constructor(private domSanitizer: DomSanitizer, private dataService: DataService) {}
7475

7576
ngOnInit(): void {
77+
this.dataService.loading$.subscribe((isLoading) => {
78+
this.loading = isLoading;
79+
});
80+
7681
this.dataSubscription = this.dataService.fetchData(this.state).subscribe((result) => {
7782
this.gridView = result;
7883
});
@@ -91,7 +96,11 @@ export class DynamicGridComponent {
9196

9297
public onGridSizeChange(event: { text: string; value: number }): void {
9398
this.currentGridDataSize = event;
99+
this.loading = true;
94100
this.dataService.updateTotalRecords(event.value);
101+
setTimeout(() => {
102+
this.loading = false;
103+
}, 300);
95104
}
96105

97106
public onRefreshIntervalChange(event: number): void {

examples-standalone/kendoangular-landing-page/src/app/services/data.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export class DataService {
1919
private totalRecords: number = 100;
2020
private updateInterval: number = 100;
2121

22+
private loadingSubject = new BehaviorSubject<boolean>(false);
23+
public loading$ = this.loadingSubject.asObservable();
24+
2225
private dataSubject = new BehaviorSubject<DynamicGridItem[]>([]);
2326
private _total: number = 0;
2427
private gridState: State = {
@@ -36,6 +39,8 @@ export class DataService {
3639
}
3740

3841
public fetchData(state?: State): Observable<GridDataResult> {
42+
this.loadingSubject.next(true);
43+
3944
if (state) {
4045
this.gridState = { ...state };
4146
}
@@ -53,6 +58,8 @@ export class DataService {
5358
// Start new interval with current settings
5459
this.startDataRefresh();
5560

61+
setTimeout(() => this.loadingSubject.next(false), 300);
62+
5663
// Return the observable that will receive updates
5764
return this.dataSubject.asObservable().pipe(map((data) => ({ data: data, total: this._total })));
5865
}

0 commit comments

Comments
 (0)