Skip to content

Commit

Permalink
fix(metrics): use onRowCountChanged event to refresh metrics fix #715
Browse files Browse the repository at this point in the history
… (#716)

- fixes issue #715
  • Loading branch information
ghiscoding committed Mar 17, 2021
1 parent 392304c commit f123854
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --port 4300 --open",
"start": "ng serve --port 4300",
"postinstall": "ngcc",
"prebuild": "npm-run-all delete:dist",
"build": "npm run packagr",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,13 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn

if (dataView && grid) {
// When data changes in the DataView, we need to refresh the metrics and/or display a warning if the dataset is empty
this._eventHandler.subscribe(dataView.onRowsOrCountChanged, (_e: Event, args: any) => {
this._eventHandler.subscribe(dataView.onRowCountChanged, (_e: Event, args: any) => {
grid.invalidate();
this.handleOnItemCountChanged(args.currentRowCount || 0);
this.handleOnItemCountChanged(args.current || 0, this.dataView.getItemCount());
});
this._eventHandler.subscribe(dataView.onSetItemsCalled, (_e: Event, args: any) => {
grid.invalidate();
this.handleOnItemCountChanged(this.dataView.getLength(), args.itemCount);
});

// Tree Data with Pagiantion is not supported, throw an error when user tries to do that
Expand Down Expand Up @@ -772,17 +776,17 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
}

/** When data changes in the DataView, we'll refresh the metrics and/or display a warning if the dataset is empty */
private handleOnItemCountChanged(itemCount: number) {
private handleOnItemCountChanged(currentPageRowItemCount: number, totalItemCount: number) {
this.metrics = {
startTime: new Date(),
endTime: new Date(),
itemCount: itemCount,
totalItemCount: this.dataView && this.dataView.getItemCount() || 0
itemCount: currentPageRowItemCount,
totalItemCount
};

// when using local (in-memory) dataset, we'll display a warning message when filtered data is empty
if (this._isLocalGrid && this.gridOptions && this.gridOptions.enableEmptyDataWarningMessage) {
this.displayEmptyDataWarning(itemCount === 0);
this.displayEmptyDataWarning(currentPageRowItemCount === 0);
}
}

Expand Down

0 comments on commit f123854

Please sign in to comment.