Skip to content

Commit 4fbc2dc

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Fix unmerge when roots of merge groups partially overlap.
1 parent 3b3b3f8 commit 4fbc2dc

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

projects/igniteui-angular/src/lib/grids/grid/grid.pipes.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,31 @@ export class IgxGridUnmergeActivePipe implements PipeTransform {
129129
// if nothing to update, return
130130
return collection;
131131
}
132-
let result = cloneArray(collection) as any;
132+
133+
// collect full range of data to unmerge
134+
const dataToUnmerge = new Set();
135+
let startIndex;
133136
uniqueRoots.forEach(x => {
134137
const index = collection.indexOf(x);
138+
if (!startIndex) {
139+
startIndex = index;
140+
} else {
141+
startIndex = Math.min(startIndex, index);
142+
}
143+
dataToUnmerge.add(x.recordRef);
135144
const colKeys = [...x.cellMergeMeta.keys()];
136145
const cols = colsToMerge.filter(col => colKeys.indexOf(col.field) !== -1);
137-
let data = [];
138146
for (const col of cols) {
139-
140-
let childData = x.cellMergeMeta.get(col.field).childRecords;
147+
const childData = x.cellMergeMeta.get(col.field).childRecords;
141148
const childRecs = childData.map(rec => rec.recordRef);
142-
data = data.concat([x.recordRef, ...childRecs]);
149+
childRecs.forEach(child => dataToUnmerge.add(child));
143150
}
144-
const res = DataUtil.merge(Array.from(new Set(data)), cols, this.grid.mergeStrategy, activeRowIndexes.map(ri => ri - index), this.grid);
145-
result = result.slice(0, index).concat(res, result.slice(index + res.length));
146151
});
147152

148-
149-
return result;
153+
// unmerge data where active row index breaks merge groups
154+
const res = DataUtil.merge(Array.from(dataToUnmerge), colsToMerge, this.grid.mergeStrategy, activeRowIndexes.map(ri => ri - startIndex), this.grid);
155+
collection = collection.slice(0, startIndex).concat(res, collection.slice(startIndex + res.length));
156+
return collection;
150157
}
151158
}
152159

0 commit comments

Comments
 (0)