@@ -10,7 +10,7 @@ import { FilterUtil, IFilteringStrategy } from '../../data-operations/filtering-
1010import { ISortingExpression } from '../../data-operations/sorting-strategy' ;
1111import { IGridSortingStrategy , IGridGroupingStrategy } from '../common/strategy' ;
1212import { GridCellMergeMode , RowPinningPosition } from '../common/enums' ;
13- import { IGridMergeStrategy } from '../../data-operations/merge-strategy' ;
13+ import { IGridMergeStrategy , IMergeByResult } from '../../data-operations/merge-strategy' ;
1414
1515/**
1616 * @hidden
@@ -130,33 +130,44 @@ export class IgxGridUnmergeActivePipe implements PipeTransform {
130130 return collection ;
131131 }
132132
133- // collect full range of data to unmerge
134- let startIndex ;
135- let endIndex ;
133+ let result = cloneArray ( collection ) as any ;
136134 uniqueRoots . forEach ( x => {
137135 const index = collection . indexOf ( x ) ;
138- if ( ! startIndex ) {
139- startIndex = index ;
140- } else {
141- startIndex = Math . min ( startIndex , index ) ;
142- }
143136 const colKeys = [ ...x . cellMergeMeta . keys ( ) ] ;
144137 const cols = colsToMerge . filter ( col => colKeys . indexOf ( col . field ) !== - 1 ) ;
145138 for ( const col of cols ) {
146139 const childData = x . cellMergeMeta . get ( col . field ) . childRecords ;
147140 const childRecs = childData . map ( rec => rec . recordRef ) ;
148- if ( ! endIndex ) {
149- endIndex = index + childRecs . length ;
150- } else {
151- endIndex = Math . max ( endIndex , index + childRecs . length + 1 ) ;
141+ if ( childRecs . length === 0 ) {
142+ // nothing to unmerge
143+ continue ;
144+ }
145+ const unmergedData = DataUtil . merge ( [ x . recordRef , ...childRecs ] , [ col ] , this . grid . mergeStrategy , activeRowIndexes . map ( ri => ri - index ) , this . grid ) ;
146+ for ( let i = 0 ; i < unmergedData . length ; i ++ ) {
147+ const unmergedRec = unmergedData [ i ] ;
148+ const origRecord = result [ index + i ] ;
149+ if ( unmergedRec . cellMergeMeta ?. get ( col . field ) ) {
150+ // deep clone of object, since we don't want to pollute the original fully merged collection.
151+ const objCopy = {
152+ recordRef : origRecord . recordRef ,
153+ ghostRecord : origRecord . ghostRecord ,
154+ cellMergeMeta : new Map < string , IMergeByResult > ( )
155+ } ;
156+ // deep clone of inner map
157+ for ( const [ key , value ] of origRecord . cellMergeMeta ) {
158+ objCopy . cellMergeMeta . set ( key , structuredClone ( value ) ) ;
159+ }
160+ // update copy with new meta from unmerged data record, but just for this column
161+ objCopy . cellMergeMeta ?. set ( col . field , unmergedRec . cellMergeMeta . get ( col . field ) ) ;
162+ result [ index + i ] = objCopy ;
163+ } else {
164+ // this is the unmerged record, with no merge metadata
165+ result [ index + i ] = unmergedRec ;
166+ }
152167 }
153168 }
154169 } ) ;
155- const dataToUnmerge = collection . slice ( startIndex , endIndex ) . map ( x => x . recordRef ) ;
156- // unmerge data where active row index breaks merge groups
157- const res = DataUtil . merge ( dataToUnmerge , colsToMerge , this . grid . mergeStrategy , activeRowIndexes . map ( ri => ri - startIndex ) , this . grid ) ;
158- collection = collection . slice ( 0 , startIndex ) . concat ( res , collection . slice ( startIndex + res . length ) ) ;
159- return collection ;
170+ return result ;
160171 }
161172}
162173
0 commit comments