diff --git a/projects/igniteui-angular/src/lib/grids/selection/selection.service.ts b/projects/igniteui-angular/src/lib/grids/selection/selection.service.ts index aedfaee3f31..0d35bad66d1 100644 --- a/projects/igniteui-angular/src/lib/grids/selection/selection.service.ts +++ b/projects/igniteui-angular/src/lib/grids/selection/selection.service.ts @@ -439,7 +439,7 @@ export class IgxGridSelectionService { /** Select all rows, if filtering is applied select only from filtered data. */ public selectAllRows(event?) { - const addedRows = this.allData.filter((row) => !this.isRowSelected(this.getRecordKey(row))); + const addedRows = this.allData.filter((row) => !this.rowSelection.has(this.getRecordKey(row))); const selectedRows = this.getSelectedRowsData(); const newSelection = this.rowSelection.size ? selectedRows.concat(addedRows) : addedRows; this.indeterminateRows.clear(); @@ -616,10 +616,8 @@ export class IgxGridSelectionService { if (this.allRowsSelected !== undefined && !newSelection) { return this.allRowsSelected; } - const selectedData = new Set(newSelection ? newSelection : [...this.rowSelection]); - const allData = this.getRowIDs(this.allData); - const unSelectedRows = allData.filter(row => !selectedData.has(row)); - return this.allRowsSelected = this.allData.length > 0 && unSelectedRows.length === 0; + const selectedData = new Set(this.getRowIDs(newSelection || this.rowSelection)); + return this.allRowsSelected = this.allData.length > 0 && this.allData.every(row => selectedData.has(this.getRecordKey(row))); } public hasSomeRowSelected(): boolean { @@ -639,13 +637,16 @@ export class IgxGridSelectionService { if (this.areEqualCollections(currSelection, newSelection)) { return; } + const args: IRowSelectionEventArgs = { owner: this.grid, oldSelection: currSelection, newSelection, - added, removed, - event, cancel: false, - allRowsSelected: this.areAllRowSelected(newSelection.map(r => this.getRecordKey(r))) + added, + removed, + event, + cancel: false, + allRowsSelected: this.areAllRowSelected(newSelection) }; this.grid.rowSelectionChanging.emit(args);