diff --git a/projects/igniteui-angular/src/lib/grids/api.service.ts b/projects/igniteui-angular/src/lib/grids/api.service.ts index 498eeb1b6b0..8b14408d371 100644 --- a/projects/igniteui-angular/src/lib/grids/api.service.ts +++ b/projects/igniteui-angular/src/lib/grids/api.service.ts @@ -599,4 +599,20 @@ export class GridBaseAPIService { const grid = this.get(id); return grid.primaryKey ? rowData[grid.primaryKey] : rowData; } + + public row_deleted_transaction(id: string, rowID: any): boolean { + const grid = this.get(id); + if (!grid) { + return false; + } + if (!grid.transactions.enabled) { + return false; + } + const state = grid.transactions.getState(rowID); + if (state) { + return state.type === TransactionType.DELETE; + } + + return false; + } } 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 40e1bb6fad8..6e7cb1fc323 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts @@ -3323,8 +3323,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements * @hidden */ public refreshGridState(args?) { - this.endEdit(true); - this.summaryService.clearSummaryCache(args); + this.endEdit(true); + this.summaryService.clearSummaryCache(args); } // TODO: We have return values here. Move them to event args ?? @@ -3818,7 +3818,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements protected _disableMultipleSummaries(expressions) { expressions.forEach((column) => { const columnName = column && column.fieldName ? column.fieldName : column; - this._summaries(columnName, false); }); + this._summaries(columnName, false); + }); } /** @@ -4044,7 +4045,13 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements */ public selectRows(rowIDs: any[], clearCurrentSelection?: boolean) { let newSelection: Set; - newSelection = this.selection.add_items(this.id, rowIDs, clearCurrentSelection); + let selectableRows = []; + if (this.transactions.enabled) { + selectableRows = rowIDs.filter(e => !this.gridAPI.row_deleted_transaction(this.id, e)); + } else { + selectableRows = rowIDs; + } + newSelection = this.selection.add_items(this.id, selectableRows, clearCurrentSelection); this.triggerRowSelectionChange(newSelection); } diff --git a/projects/igniteui-angular/src/lib/grids/grid/grid-row.component.html b/projects/igniteui-angular/src/lib/grids/grid/grid-row.component.html index 77dea99fe0e..64890eb6d68 100644 --- a/projects/igniteui-angular/src/lib/grids/grid/grid-row.component.html +++ b/projects/igniteui-angular/src/lib/grids/grid/grid-row.component.html @@ -3,7 +3,7 @@
- +
diff --git a/projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts b/projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts index db311095766..a88cd5842ba 100644 --- a/projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts +++ b/projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts @@ -762,7 +762,7 @@ describe('IgxGrid Component Tests', () => { const grid = fix.componentInstance.grid; expect(grid.columns[1].width).toEqual('150'); expect(grid.columns[1].width).toEqual('150'); - }); + }); }); describe('IgxGrid - API methods', () => { @@ -2961,6 +2961,22 @@ describe('IgxGrid Component Tests', () => { expect(grid.page).toEqual(1); expect(grid.totalPages).toEqual(2); })); + + it('Should not allow selecting rows that are deleted', fakeAsync(() => { + const fixture = TestBed.createComponent(IgxGridRowEditingTransactionComponent); + fixture.detectChanges(); + const grid = fixture.componentInstance.grid; + grid.rowSelectable = true; + fixture.detectChanges(); + + grid.deleteRowById(2); + grid.deleteRowById(3); + + fixture.detectChanges(); + grid.selectRows([2, 3, 4]); + fixture.detectChanges(); + expect(grid.selectedRows()).toEqual([4]); + })); }); describe('Row Editing - Grouping', () => { diff --git a/projects/igniteui-angular/src/lib/grids/row.component.ts b/projects/igniteui-angular/src/lib/grids/row.component.ts index 9ab955de0b8..e382bf1871e 100644 --- a/projects/igniteui-angular/src/lib/grids/row.component.ts +++ b/projects/igniteui-angular/src/lib/grids/row.component.ts @@ -160,7 +160,7 @@ export class IgxRowComponent implements DoCheck /** @hidden */ public get deleted(): boolean { - return this.isRowDeleted(); + return this.gridAPI.row_deleted_transaction(this.gridID, this.rowID); } public get inEditMode(): boolean { @@ -320,13 +320,4 @@ export class IgxRowComponent implements DoCheck const deletedClass = this.deleted ? 'igx-grid__tr--deleted' : ''; return `${this.defaultCssClass} ${indexClass} ${selectedClass} ${editClass} ${dirtyClass} ${deletedClass}`.trim(); } - - protected isRowDeleted(): boolean { - const state: State = this.grid.transactions.getState(this.rowID); - if (state) { - return state.type === TransactionType.DELETE; - } - - return false; - } } diff --git a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-api.service.ts b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-api.service.ts index 4cb76ce2ff2..e0058f34d7e 100644 --- a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-api.service.ts +++ b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-api.service.ts @@ -5,7 +5,7 @@ import { ITreeGridRecord } from './tree-grid.interfaces'; import { IRowToggleEventArgs } from './tree-grid.interfaces'; import { IgxColumnComponent } from '../column.component'; import { first } from 'rxjs/operators'; -import { HierarchicalTransaction, TransactionType } from '../../services'; +import { HierarchicalTransaction, TransactionType, State } from '../../services'; import { mergeObjects } from '../../core/utils'; export class IgxTreeGridAPIService extends GridBaseAPIService { @@ -174,4 +174,26 @@ export class IgxTreeGridAPIService extends GridBaseAPIService { expect(trans.add).toHaveBeenCalledTimes(2); expect(trans.add).toHaveBeenCalledWith(transPasrams, null); })); + + it('Should NOT select deleted rows through API - Hierarchical DS', fakeAsync(() => { + fix = TestBed.createComponent(IgxTreeGridRowEditingHierarchicalDSTransactionComponent); + fix.detectChanges(); + treeGrid = fix.componentInstance.treeGrid; + + treeGrid.rowSelectable = true; + tick(); + fix.detectChanges(); + /** Select deleted row */ + treeGrid.deleteRowById(663); + tick(); + fix.detectChanges(); + expect(treeGrid.selectedRows()).toEqual([]); + treeGrid.selectRows([663]); + tick(); + fix.detectChanges(); + expect(treeGrid.selectedRows()).toEqual([]); + /** Select row with deleted parent */ + treeGrid.deleteRowById(147); + tick(); + fix.detectChanges(); + // 147 -> 475 + treeGrid.selectRows([475]); + tick(); + fix.detectChanges(); + expect(treeGrid.selectedRows()).toEqual([]); + })); + + it('Should NOT select deleted rows through API - Flat DS', fakeAsync(() => { + fix = TestBed.createComponent(IgxTreeGridRowEditingTransactionComponent); + fix.detectChanges(); + treeGrid = fix.componentInstance.treeGrid; + + treeGrid.rowSelectable = true; + tick(); + fix.detectChanges(); + /** Select deleted row */ + treeGrid.deleteRowById(6); + tick(); + fix.detectChanges(); + expect(treeGrid.selectedRows()).toEqual([]); + treeGrid.selectRows([6]); + tick(); + fix.detectChanges(); + expect(treeGrid.selectedRows()).toEqual([]); + /** Select row with deleted parent */ + treeGrid.deleteRowById(10); + tick(); + fix.detectChanges(); + // 10 -> 9 + treeGrid.selectRows([9]); + tick(); + fix.detectChanges(); + expect(treeGrid.selectedRows()).toEqual([]); + })); }); describe('Multi-column header', () => { diff --git a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-row.component.html b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-row.component.html index 2fc3a915e4b..a32f9f7e41b 100644 --- a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-row.component.html +++ b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-row.component.html @@ -1,6 +1,6 @@
- +
diff --git a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-row.component.ts b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-row.component.ts index f96f54714ad..e81df6fa60c 100644 --- a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-row.component.ts +++ b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-row.component.ts @@ -3,7 +3,6 @@ import { IgxTreeGridComponent } from './tree-grid.component'; import { IgxRowComponent } from '../row.component'; import { ITreeGridRecord } from './tree-grid.interfaces'; import { IgxTreeGridAPIService } from './tree-grid-api.service'; -import { State, TransactionType } from '../../services'; import { GridBaseAPIService } from '../api.service'; import { IgxSelectionAPIService } from '../../core/selection'; @@ -86,27 +85,4 @@ export class IgxTreeGridRowComponent extends IgxRowComponent