Skip to content

Commit

Permalink
fix(grid): proper check for paging w/ transactions in place, #3425
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSlavov committed Dec 17, 2018
1 parent 1f1634b commit 01659cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 6 additions & 12 deletions projects/igniteui-angular/src/lib/grids/grid-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
const data = this.gridAPI.get_all_data(this.id, this.transactions.enabled);
if (this.primaryKey) {
index = data.map((record) => record[this.primaryKey]).indexOf(rowId);
} else {
Expand Down Expand Up @@ -3078,22 +3078,16 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
this.checkHeaderCheckboxStatus();
}

const addedRowsDif = this.dataWithAddedInTransactionRows.length - this.data.length;
this.deleteRowFromData(rowId, index);
this._pipeTrigger++;
this.cdr.markForCheck();

const dataAfterDelete = !this.transactions.enabled ? data : this.dataWithAddedInTransactionRows;
this.refreshSearch();
if (this.isLastPage && this.page !== 0) {
let pageSwitch = 0;
if (!this.transactions.enabled) {
pageSwitch = this.data.length % this.perPage === 0 ? 1 : 0;
} else {
if (addedRowsDif) {
pageSwitch = this.dataWithAddedInTransactionRows.length % this.perPage === 0 ? 1 : 0;
}
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;
}
this.page -= pageSwitch;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2896,7 +2896,7 @@ describe('IgxGrid Component Tests', () => {
fixture.detectChanges();
// This is behaving incorrectly - if there is only 1 transaction and it is an ADD transaction on the last page
// Deleting the ADD transaction on the last page will trigger grid.page-- TWICE
expect(grid.page).toEqual(0); // Should be 1
expect(grid.page).toEqual(1); // Should be 1
expect(grid.totalPages).toEqual(2);
}));

Expand Down

0 comments on commit 01659cc

Please sign in to comment.