From 6fb83806ec0c3b4fb2422781886317c1b215b0b7 Mon Sep 17 00:00:00 2001 From: ViktorSlavov Date: Tue, 18 Dec 2018 17:13:25 +0200 Subject: [PATCH] refactor(grid): add comment to row delete+paging, change check for page, #3425 --- .../src/lib/grids/grid-base.component.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts index a8006f8d078..4ec424bc82a 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts @@ -3049,7 +3049,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements /** @hidden */ public deleteRowById(rowId: any) { let index: number; - const data = this.gridAPI.get_all_data(this.id, this.transactions.enabled); + const data = this.gridAPI.get_all_data(this.id); if (this.primaryKey) { index = data.map((record) => record[this.primaryKey]).indexOf(rowId); } else { @@ -3081,13 +3081,12 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements this.deleteRowFromData(rowId, index); this._pipeTrigger++; this.cdr.markForCheck(); - const dataAfterDelete = !this.transactions.enabled ? data : this.dataWithAddedInTransactionRows; + // Data needs to be recalculated if transactions are in place + // If no transactions, `data` will be a reference to the grid getter, otherwise it will be stale + const dataAfterDelete = this.transactions.enabled ? this.dataWithAddedInTransactionRows : data; this.refreshSearch(); - if (dataAfterDelete.length % this.perPage === 0 && this.isLastPage && this.page !== 0) { - const currentPage = Math.ceil(dataAfterDelete.length / this.perPage) - 1; - if (this.page !== currentPage) { - this.page = currentPage; - } + if (dataAfterDelete.length % this.perPage === 0 && dataAfterDelete.length / this.perPage - 1 < this.page && this.page !== 0) { + this.page--; } }