@@ -86,14 +86,76 @@ export class IgxGridCellMergePipe implements PipeTransform {
8686
8787 constructor ( @Inject ( IGX_GRID_BASE ) private grid : GridType ) { }
8888
89- public transform ( collection : any , colsToMerge : ColumnType [ ] , mergeMode : GridCellMergeMode , mergeStrategy : IGridMergeStrategy , activeRowIndexes : number [ ] , pinned : boolean , _pipeTrigger : number ) {
89+ public transform ( collection : any , colsToMerge : ColumnType [ ] , mergeMode : GridCellMergeMode , mergeStrategy : IGridMergeStrategy , _pipeTrigger : number ) {
90+ if ( colsToMerge . length === 0 ) {
91+ return collection ;
92+ }
93+ const result = DataUtil . merge ( collection , colsToMerge , mergeStrategy , [ ] , this . grid ) ;
94+ return result ;
95+ }
96+ }
97+
98+ @Pipe ( {
99+ name : 'gridUnmergeActive' ,
100+ standalone : true
101+ } )
102+ export class IgxGridUnmergeActivePipe implements PipeTransform {
103+
104+ constructor ( @Inject ( IGX_GRID_BASE ) private grid : GridType ) { }
105+
106+ public transform ( collection : any , colsToMerge : ColumnType [ ] , activeRowIndexes : number [ ] , pinned : boolean , _pipeTrigger : number ) {
90107 if ( colsToMerge . length === 0 ) {
91108 return collection ;
92109 }
93110 if ( this . grid . hasPinnedRecords && ! pinned && this . grid . pinning . rows !== RowPinningPosition . Bottom ) {
94111 activeRowIndexes = activeRowIndexes . map ( x => x - this . grid . pinnedRecordsCount ) ;
95112 }
96- const result = DataUtil . merge ( cloneArray ( collection ) , colsToMerge , mergeStrategy , activeRowIndexes , this . grid ) ;
113+ activeRowIndexes = Array . from ( new Set ( activeRowIndexes ) ) . filter ( x => ! isNaN ( x ) ) ;
114+ const rootsToUpdate = [ ] ;
115+ activeRowIndexes . forEach ( index => {
116+ const target = collection [ index ] ;
117+ if ( target ) {
118+ colsToMerge . forEach ( col => {
119+ const colMeta = target . cellMergeMeta . get ( col . field ) ;
120+ const root = colMeta . root || ( colMeta . rowSpan > 1 ? target : null ) ;
121+ if ( root ) {
122+ rootsToUpdate . push ( root ) ;
123+ }
124+ } ) ;
125+ }
126+ } ) ;
127+ const uniqueRoots = Array . from ( new Set ( rootsToUpdate ) ) ;
128+ if ( uniqueRoots . length === 0 ) {
129+ // if nothing to update, return
130+ return collection ;
131+ }
132+ let result = cloneArray ( collection ) as any ;
133+ uniqueRoots . forEach ( x => {
134+ const index = result . indexOf ( x ) ;
135+ const colKeys = [ ...x . cellMergeMeta . keys ( ) ] ;
136+ const cols = colsToMerge . filter ( col => colKeys . indexOf ( col . field ) !== - 1 ) ;
137+ let res = [ ] ;
138+ for ( const col of cols ) {
139+
140+ let childData = x . cellMergeMeta . get ( col . field ) . childRecords ;
141+ const childRecs = childData . map ( rec => rec . recordRef ) ;
142+ const isDate = col ?. dataType === 'date' || col ?. dataType === 'dateTime' ;
143+ const isTime = col ?. dataType === 'time' || col ?. dataType === 'dateTime' ;
144+ res = this . grid . mergeStrategy . merge (
145+ [ x . recordRef , ...childRecs ] ,
146+ col . field ,
147+ col . mergingComparer ,
148+ res ,
149+ activeRowIndexes . map ( ri => ri - index ) ,
150+ isDate ,
151+ isTime ,
152+ this . grid ) ;
153+
154+ }
155+ result = result . slice ( 0 , index ) . concat ( res , result . slice ( index + res . length ) ) ;
156+ } ) ;
157+
158+
97159 return result ;
98160 }
99161}
0 commit comments