Skip to content

Commit 096f47c

Browse files
Merge pull request #14610 from IgniteUI/ganastasov/feat-14519-master
feat(grid): optimize grid row selection flow and performance - master
2 parents 0d8fc06 + ccc2721 commit 096f47c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

projects/igniteui-angular/src/lib/grids/selection/selection.service.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export class IgxGridSelectionService {
439439

440440
/** Select all rows, if filtering is applied select only from filtered data. */
441441
public selectAllRows(event?) {
442-
const addedRows = this.allData.filter((row) => !this.isRowSelected(this.getRecordKey(row)));
442+
const addedRows = this.allData.filter((row) => !this.rowSelection.has(this.getRecordKey(row)));
443443
const selectedRows = this.getSelectedRowsData();
444444
const newSelection = this.rowSelection.size ? selectedRows.concat(addedRows) : addedRows;
445445
this.indeterminateRows.clear();
@@ -616,10 +616,8 @@ export class IgxGridSelectionService {
616616
if (this.allRowsSelected !== undefined && !newSelection) {
617617
return this.allRowsSelected;
618618
}
619-
const selectedData = new Set(newSelection ? newSelection : [...this.rowSelection]);
620-
const allData = this.getRowIDs(this.allData);
621-
const unSelectedRows = allData.filter(row => !selectedData.has(row));
622-
return this.allRowsSelected = this.allData.length > 0 && unSelectedRows.length === 0;
619+
const selectedData = new Set(this.getRowIDs(newSelection || this.rowSelection));
620+
return this.allRowsSelected = this.allData.length > 0 && this.allData.every(row => selectedData.has(this.getRecordKey(row)));
623621
}
624622

625623
public hasSomeRowSelected(): boolean {
@@ -639,13 +637,16 @@ export class IgxGridSelectionService {
639637
if (this.areEqualCollections(currSelection, newSelection)) {
640638
return;
641639
}
640+
642641
const args: IRowSelectionEventArgs = {
643642
owner: this.grid,
644643
oldSelection: currSelection,
645644
newSelection,
646-
added, removed,
647-
event, cancel: false,
648-
allRowsSelected: this.areAllRowSelected(newSelection.map(r => this.getRecordKey(r)))
645+
added,
646+
removed,
647+
event,
648+
cancel: false,
649+
allRowsSelected: this.areAllRowSelected(newSelection)
649650
};
650651

651652
this.grid.rowSelectionChanging.emit(args);

0 commit comments

Comments
 (0)