Skip to content

Commit 3674f8d

Browse files
authored
fix(IgxGrid): Don't use spread operator for large collections. (#15915)
1 parent dd32969 commit 3674f8d

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

projects/igniteui-angular/src/lib/grids/common/strategy.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class IgxSorting implements IGridSortingStrategy {
7676
grid: GridType = null,
7777
groupsRecords: any[] = [],
7878
fullResult: IGroupByResult = { data: [], metadata: [] }
79-
): any[] {
79+
): IGroupByResult {
8080
const expressions = state.expressions;
8181
const expansion = state.expansion;
8282
let i = 0;
@@ -117,23 +117,24 @@ export class IgxSorting implements IGridSortingStrategy {
117117
fullResult.metadata.push(null);
118118
if (level < expressions.length - 1) {
119119
recursiveResult = this.groupDataRecursive(group, state, level + 1, groupRow,
120-
expanded ? metadata : [], grid, groupsRecords, fullResult);
120+
[], grid, groupsRecords, fullResult);
121121
if (expanded) {
122-
result = result.concat(recursiveResult);
122+
result = result.concat(recursiveResult.data);
123+
metadata = metadata.concat(recursiveResult.metadata);
123124
}
124125
} else {
125126
for (const groupItem of group) {
126127
fullResult.metadata.push(groupRow);
127128
fullResult.data.push(groupItem);
128129
}
129130
if (expanded) {
130-
metadata.push(...fullResult.metadata.slice(fullResult.metadata.length - group.length));
131-
result.push(...fullResult.data.slice(fullResult.data.length - group.length));
131+
metadata = metadata.concat(fullResult.metadata.slice(fullResult.metadata.length - group.length));
132+
result = result.concat(fullResult.data.slice(fullResult.data.length - group.length));
132133
}
133134
}
134135
i += group.length;
135136
}
136-
return result;
137+
return { data: result, metadata };
137138
}
138139

139140
/**
@@ -264,8 +265,8 @@ export class IgxGrouping extends IgxSorting implements IGridGroupingStrategy {
264265
const grouping = this.groupDataRecursive(data, state, 0, null, metadata, grid, groupsRecords, fullResult);
265266
grid?.groupingPerformedSubject.next();
266267
return {
267-
data: grouping,
268-
metadata
268+
data: grouping.data,
269+
metadata: grouping.metadata
269270
};
270271
}
271272
}

projects/igniteui-angular/src/lib/grids/grid/grid.groupby.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,6 +3822,32 @@ describe('IgxGrid - GroupBy #grid', () => {
38223822
}
38233823
});
38243824

3825+
it('should be able to build groups with 100 000+ records', () => {
3826+
const fix = TestBed.createComponent(GroupableGridComponent);
3827+
const grid = fix.componentInstance.instance;
3828+
3829+
const data = [];
3830+
for (let i = 0; i < 1000000; i++) {
3831+
data.push({
3832+
Downloads: i,
3833+
ID: 1,
3834+
ProductName: 'Test'
3835+
});
3836+
}
3837+
3838+
fix.componentInstance.data = data;
3839+
fix.detectChanges();
3840+
3841+
grid.groupBy({
3842+
fieldName: 'ProductName',
3843+
dir: SortingDirection.Asc
3844+
});
3845+
fix.detectChanges();
3846+
3847+
let groupRows = grid.groupsRowList.toArray();
3848+
checkGroups(groupRows, ['Test']);
3849+
});
3850+
38253851
describe('GroupBy with state directive', () => {
38263852
let fix: ComponentFixture<GridGroupByStateComponent>;
38273853
let state: IgxGridStateDirective;

0 commit comments

Comments
 (0)