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

Commit 7b95401

Browse files
authored
fix(metrics): refresh metrics also when providing new data to DataView (#677)
1 parent 9ded204 commit 7b95401

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -624,20 +624,15 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
624624
this.gridEventService.bindOnClick(grid, dataView);
625625

626626
if (dataView && grid) {
627-
this._eventHandler.subscribe(dataView.onRowCountChanged, (e: Event, args: any) => {
628-
grid.invalidate();
629-
630-
this.metrics = {
631-
startTime: new Date(),
632-
endTime: new Date(),
633-
itemCount: args && args.current || 0,
634-
totalItemCount: Array.isArray(this.dataset) ? this.dataset.length : 0
635-
};
627+
// When data changes in the DataView, we need to refresh the metrics and/or display a warning if the dataset is empty
628+
// we will do that via the following 2 handlers (onSetItemsCalled, onRowCountChanged)
629+
this._eventHandler.subscribe(dataView.onSetItemsCalled, () => {
630+
this.handleOnItemsChanged(this.dataset.length);
631+
});
636632

637-
// when using local (in-memory) dataset, we'll display a warning message when filtered data is empty
638-
if (this._isLocalGrid && this.gridOptions && this.gridOptions.enableEmptyDataWarningMessage) {
639-
this.displayEmptyDataWarning(args.current === 0);
640-
}
633+
this._eventHandler.subscribe(dataView.onRowCountChanged, (_e: Event, args: any) => {
634+
grid.invalidate();
635+
this.handleOnItemsChanged(args.current || 0);
641636
});
642637

643638
// Tree Data with Pagiantion is not supported, throw an error when user tries to do that
@@ -776,6 +771,21 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
776771
}
777772
}
778773

774+
/** When data changes in the DataView, we'll refresh the metrics and/or display a warning if the dataset is empty */
775+
private handleOnItemsChanged(itemCount: number) {
776+
this.metrics = {
777+
startTime: new Date(),
778+
endTime: new Date(),
779+
itemCount: itemCount,
780+
totalItemCount: Array.isArray(this.dataset) ? this.dataset.length : 0
781+
};
782+
783+
// when using local (in-memory) dataset, we'll display a warning message when filtered data is empty
784+
if (this._isLocalGrid && this.gridOptions && this.gridOptions.enableEmptyDataWarningMessage) {
785+
this.displayEmptyDataWarning(itemCount === 0);
786+
}
787+
}
788+
779789
private initializePaginationService(paginationOptions: Pagination) {
780790
if (this.gridOptions) {
781791
this.paginationData = {

0 commit comments

Comments
 (0)