Skip to content

Commit 0aa9e9e

Browse files
authored
Improve row selection performance when primaryKey is set --18 (#14522)
* fix(grid): improve performance for rowSelection when primaryKey is set #14444 * chore(*): enable rowSelection for grid performance sample * chore(*): fix typo in code
1 parent 780201f commit 0aa9e9e

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,10 @@ export class IgxGridSelectionService {
400400
return Array.from(this.rowSelection);
401401
}
402402
const selection = [];
403+
const gridDataMap = {};
404+
this.grid.gridAPI.get_all_data(true).forEach(row => gridDataMap[this.getRecordKey(row)] = row);
403405
this.rowSelection.forEach(rID => {
404-
const rData = this.grid.gridAPI.get_all_data(true).find(row => this.getRecordKey(row) === rID);
406+
const rData = gridDataMap[rID];
405407
const partialRowData = {};
406408
partialRowData[this.grid.primaryKey] = rID;
407409
selection.push(rData ? rData : partialRowData);
@@ -607,9 +609,9 @@ export class IgxGridSelectionService {
607609
if (this.allRowsSelected !== undefined && !newSelection) {
608610
return this.allRowsSelected;
609611
}
610-
const selectedData = newSelection ? newSelection : [...this.rowSelection]
612+
const selectedData = new Set(newSelection ? newSelection : [...this.rowSelection]);
611613
const allData = this.getRowIDs(this.allData);
612-
const unSelectedRows = allData.filter(row => !selectedData.includes(row));
614+
const unSelectedRows = allData.filter(row => !selectedData.has(row));
613615
return this.allRowsSelected = this.allData.length > 0 && unSelectedRows.length === 0;
614616
}
615617

src/app/grid-performance/grid-performance.sample.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div style="height: 100vh; width: 100wh">
22
<h4 class="sample-title"> Fixed Size Rows</h4>
3-
<igx-grid #grid1 [rowHeight]="20" [data]="localData" [rowSelection]="selectionMode" [allowFiltering]="true" [filterMode]="'excelStyleFilter'">
3+
<igx-grid #grid1 primaryKey="ID" [rowHeight]="20" [data]="localData" [rowSelection]="selectionMode" [allowFiltering]="true" [filterMode]="'excelStyleFilter'">
44
<igx-grid-toolbar>
55
<igx-grid-toolbar-actions>
66
<igx-grid-toolbar-pinning></igx-grid-toolbar-pinning>

src/app/grid-performance/grid-performance.sample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class GridPerformanceSampleComponent implements OnInit {
2121
public selectionMode;
2222

2323
public ngOnInit() {
24-
this.selectionMode = GridSelectionMode.none;
24+
this.selectionMode = GridSelectionMode.multiple;
2525
const cols = [];
2626
cols.push({
2727
field: 'ID',

0 commit comments

Comments
 (0)