@@ -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