From a165d9a54099d4e8dd48c9e469633d5829351437 Mon Sep 17 00:00:00 2001 From: NikolayAlipiev Date: Thu, 6 Dec 2018 14:51:27 +0200 Subject: [PATCH 1/2] fix(igx-combo): deselect child rows for nested data #3068 --- .../src/lib/core/selection.ts | 2 +- .../grids/tree-grid/tree-grid-api.service.ts | 14 ++++++++++++++ .../tree-grid/tree-grid-selection.spec.ts | 19 +++++++++++++++++++ .../grids/tree-grid/tree-grid.component.ts | 7 +++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/projects/igniteui-angular/src/lib/core/selection.ts b/projects/igniteui-angular/src/lib/core/selection.ts index 1835316806c..41ce9496d79 100644 --- a/projects/igniteui-angular/src/lib/core/selection.ts +++ b/projects/igniteui-angular/src/lib/core/selection.ts @@ -208,7 +208,7 @@ export class IgxSelectionAPIService { * @returns If all items are selected. */ public are_all_selected(componentID: string, dataCount: number): boolean { - return this.size(componentID) === dataCount; + return dataCount > 0 && dataCount === this.size(componentID); } /** 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 d7c56066018..d12129c2907 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 @@ -123,4 +123,18 @@ export class IgxTreeGridAPIService extends GridBaseAPIService { TreeGridFunctions.verifyHeaderCheckboxSelection(fix, false); }); + it('when all items are selected and then some of the selected rows are deleted, still all the items should be selected', () => { + treeGrid.selectAllRows(); + fix.detectChanges(); + TreeGridFunctions.verifyHeaderCheckboxSelection(fix, true); + + treeGrid.deleteRowById(treeGrid.selectedRows()[0]); + fix.detectChanges(); + TreeGridFunctions.verifyHeaderCheckboxSelection(fix, true); + + treeGrid.deleteRowById(treeGrid.selectedRows()[0]); + fix.detectChanges(); + TreeGridFunctions.verifyHeaderCheckboxSelection(fix, true); + + treeGrid.deleteRowById(treeGrid.selectedRows()[0]); + fix.detectChanges(); + // When deleting the last selected row, header checkbox will be unchecked. + TreeGridFunctions.verifyHeaderCheckboxSelection(fix, false); + }); + it('should be able to select row of any level', () => { treeGrid.selectRows([treeGrid.getRowByIndex(0).rowID], true); fix.detectChanges(); diff --git a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.component.ts b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.component.ts index f770e5c43ae..b2d3572a280 100644 --- a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.component.ts +++ b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.component.ts @@ -429,6 +429,13 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent { const childData = record.parent ? record.parent.data[this.childDataKey] : this.data; index = this.primaryKey ? childData.map(c => c[this.primaryKey]).indexOf(rowID) : childData.indexOf(rowID); + + const selectedChildren = []; + this._gridAPI.get_selected_children(this.id, record, selectedChildren); + if (selectedChildren.length > 0) { + this.deselectRows(selectedChildren); + } + if (this.transactions.enabled) { this.transactions.add({ id: rowID, From 52a73b3024139fe70c9a815a54436af28c2b772a Mon Sep 17 00:00:00 2001 From: NikolayAlipiev Date: Thu, 6 Dec 2018 18:55:45 +0200 Subject: [PATCH 2/2] refactor(igx-tree-grid): refactor loop #1852 --- .../src/lib/grids/tree-grid/tree-grid-api.service.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 d12129c2907..044aca3fc71 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 @@ -129,8 +129,7 @@ export class IgxTreeGridAPIService extends GridBaseAPIService