Skip to content

fix(IgxGrid): Don't use spread operator for large collections. #15915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 20.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions projects/igniteui-angular/src/lib/grids/common/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class IgxSorting implements IGridSortingStrategy {
grid: GridType = null,
groupsRecords: any[] = [],
fullResult: IGroupByResult = { data: [], metadata: [] }
): any[] {
): IGroupByResult {
const expressions = state.expressions;
const expansion = state.expansion;
let i = 0;
Expand Down Expand Up @@ -117,23 +117,24 @@ export class IgxSorting implements IGridSortingStrategy {
fullResult.metadata.push(null);
if (level < expressions.length - 1) {
recursiveResult = this.groupDataRecursive(group, state, level + 1, groupRow,
expanded ? metadata : [], grid, groupsRecords, fullResult);
[], grid, groupsRecords, fullResult);
if (expanded) {
result = result.concat(recursiveResult);
result = result.concat(recursiveResult.data);
metadata = metadata.concat(recursiveResult.metadata);
}
} else {
for (const groupItem of group) {
fullResult.metadata.push(groupRow);
fullResult.data.push(groupItem);
}
if (expanded) {
metadata.push(...fullResult.metadata.slice(fullResult.metadata.length - group.length));
result.push(...fullResult.data.slice(fullResult.data.length - group.length));
metadata = metadata.concat(fullResult.metadata.slice(fullResult.metadata.length - group.length));
result = result.concat(fullResult.data.slice(fullResult.data.length - group.length));
}
}
i += group.length;
}
return result;
return { data: result, metadata };
}

/**
Expand Down Expand Up @@ -264,8 +265,8 @@ export class IgxGrouping extends IgxSorting implements IGridGroupingStrategy {
const grouping = this.groupDataRecursive(data, state, 0, null, metadata, grid, groupsRecords, fullResult);
grid?.groupingPerformedSubject.next();
return {
data: grouping,
metadata
data: grouping.data,
metadata: grouping.metadata
};
}
}
Expand Down
26 changes: 26 additions & 0 deletions projects/igniteui-angular/src/lib/grids/grid/grid.groupby.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3822,6 +3822,32 @@ describe('IgxGrid - GroupBy #grid', () => {
}
});

it('should be able to build groups with 100 000+ records', () => {
const fix = TestBed.createComponent(GroupableGridComponent);
const grid = fix.componentInstance.instance;

const data = [];
for (let i = 0; i < 1000000; i++) {
data.push({
Downloads: i,
ID: 1,
ProductName: 'Test'
});
}

fix.componentInstance.data = data;
fix.detectChanges();

grid.groupBy({
fieldName: 'ProductName',
dir: SortingDirection.Asc
});
fix.detectChanges();

let groupRows = grid.groupsRowList.toArray();
checkGroups(groupRows, ['Test']);
});

describe('GroupBy with state directive', () => {
let fix: ComponentFixture<GridGroupByStateComponent>;
let state: IgxGridStateDirective;
Expand Down
Loading