From a115ec8247de3fa84aadaeef8dd9b8e3f1a6fa38 Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Mon, 28 Sep 2026 11:04:00 +0200 Subject: [PATCH] Fixed empty last page in Alarms, Entities and Time series table widgets when data decreases --- .../lib/alarm/alarms-table-widget.component.ts | 16 ++++++++++++++++ .../entity/entities-table-widget.component.ts | 16 ++++++++++++++++ .../lib/timeseries-table-widget.component.ts | 6 +++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts index ca03577a85..a3edee44a4 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts @@ -327,6 +327,16 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, this.paginator.firstPage(); } }); + + this.alarmsDatasource.totalPages().pipe( + debounceTime(0), + takeUntil(this.destroy$) + ).subscribe((totalPages) => { + if (this.paginator.pageIndex > 0 && this.paginator.pageIndex >= totalPages) { + this.paginator.pageIndex = Math.max(totalPages - 1, 0); + this.updateData(); + } + }); } ((this.displayPagination ? merge(this.sort.sortChange, this.paginator.page) : this.sort.sortChange) as Observable).pipe( takeUntil(this.destroy$) @@ -1401,6 +1411,12 @@ class AlarmsDatasource implements DataSource { ); } + totalPages(): Observable { + return this.pageDataSubject.pipe( + map((pageData) => pageData.totalPages) + ); + } + toggleSelection(alarm: AlarmDataInfo) { const hasValue = this.selection.hasValue(); this.selection.toggle(alarm); diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts index d222c88234..a1217c67c5 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts @@ -261,6 +261,16 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni this.paginator.firstPage(); } }); + + this.entityDatasource.totalPages().pipe( + debounceTime(0), + takeUntil(this.destroy$) + ).subscribe((totalPages) => { + if (this.paginator.pageIndex > 0 && this.paginator.pageIndex >= totalPages) { + this.paginator.pageIndex = Math.max(totalPages - 1, 0); + this.updateData(); + } + }); } ((this.displayPagination ? merge(this.sort.sortChange, this.paginator.page) : this.sort.sortChange) as Observable).pipe( takeUntil(this.destroy$) @@ -997,6 +1007,12 @@ class EntityDatasource implements DataSource { ); } + totalPages(): Observable { + return this.pageDataSubject.pipe( + map((pageData) => pageData.totalPages) + ); + } + public toggleCurrentEntity(entity: EntityData): boolean { if (this.currentEntity !== entity) { this.currentEntity = entity; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts index 9fe0ed720b..aaf6995a6b 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts @@ -1039,7 +1039,11 @@ class TimeseriesDatasource implements DataSource { switchMap(() => { return this.allRows$.pipe( map((data) => { - const fetchData = pageLink.filterData(data); + let fetchData = pageLink.filterData(data); + if (pageLink.page > 0 && pageLink.page >= fetchData.totalPages) { + pageLink.page = Math.max(fetchData.totalPages - 1, 0); + fetchData = pageLink.filterData(data); + } if (this.cellButtonActions.length) { let maxCellButtonAction: number; if (this.usedShowCellActionFunction && !this.reserveSpaceForHiddenAction) {