|
1 | 1 | import { Inject, Pipe, PipeTransform } from '@angular/core'; |
2 | | -import { IGridSortingStrategy, IGridGroupingStrategy, cloneArray, DataUtil, FilteringExpressionsTree, FilterUtil, IFilteringExpressionsTree, IFilteringStrategy, IGridMergeStrategy, IGroupByExpandState, IGroupingExpression, ISortingExpression, IGroupByResult, ColumnType } from 'igniteui-angular/core'; |
| 2 | +import { IGridSortingStrategy, IGridGroupingStrategy, cloneArray, DataUtil, FilteringExpressionsTree, FilterUtil, IFilteringExpressionsTree, IFilteringStrategy, IGridMergeStrategy, IGroupByExpandState, IGroupingExpression, ISortingExpression, IGroupByResult, ColumnType, IMergeByResult } from 'igniteui-angular/core'; |
3 | 3 | import { GridCellMergeMode, RowPinningPosition, GridType, IGX_GRID_BASE } from 'igniteui-angular/grids/core'; |
4 | 4 |
|
5 | 5 | /** |
@@ -119,33 +119,40 @@ export class IgxGridUnmergeActivePipe implements PipeTransform { |
119 | 119 | // if nothing to update, return |
120 | 120 | return collection; |
121 | 121 | } |
| 122 | + |
122 | 123 | let result = cloneArray(collection) as any; |
123 | 124 | uniqueRoots.forEach(x => { |
124 | | - const index = result.indexOf(x); |
| 125 | + const index = collection.indexOf(x); |
125 | 126 | const colKeys = [...x.cellMergeMeta.keys()]; |
126 | 127 | const cols = colsToMerge.filter(col => colKeys.indexOf(col.field) !== -1); |
127 | | - let res = []; |
128 | 128 | for (const col of cols) { |
129 | | - |
130 | | - let childData = x.cellMergeMeta.get(col.field).childRecords; |
| 129 | + const childData = x.cellMergeMeta.get(col.field).childRecords; |
131 | 130 | const childRecs = childData.map(rec => rec.recordRef); |
132 | | - const isDate = col?.dataType === 'date' || col?.dataType === 'dateTime'; |
133 | | - const isTime = col?.dataType === 'time' || col?.dataType === 'dateTime'; |
134 | | - res = this.grid.mergeStrategy.merge( |
135 | | - [x.recordRef, ...childRecs], |
136 | | - col.field, |
137 | | - col.mergingComparer, |
138 | | - res, |
139 | | - activeRowIndexes.map(ri => ri - index), |
140 | | - isDate, |
141 | | - isTime, |
142 | | - this.grid); |
143 | | - |
| 131 | + if(childRecs.length === 0) { |
| 132 | + // nothing to unmerge |
| 133 | + continue; |
| 134 | + } |
| 135 | + const unmergedData = DataUtil.merge([x.recordRef, ...childRecs], [col], this.grid.mergeStrategy, activeRowIndexes.map(ri => ri - index), this.grid); |
| 136 | + for (let i = 0; i < unmergedData.length; i++) { |
| 137 | + const unmergedRec = unmergedData[i]; |
| 138 | + const origRecord = result[index + i]; |
| 139 | + if (unmergedRec.cellMergeMeta?.get(col.field)) { |
| 140 | + // clone of object, since we don't want to pollute the original fully merged collection. |
| 141 | + const objCopy = { |
| 142 | + recordRef: origRecord.recordRef, |
| 143 | + ghostRecord: origRecord.ghostRecord, |
| 144 | + cellMergeMeta: new Map<string, IMergeByResult>(origRecord.cellMergeMeta.entries()) |
| 145 | + }; |
| 146 | + // update copy with new meta from unmerged data record, but just for this column |
| 147 | + objCopy.cellMergeMeta?.set(col.field, unmergedRec.cellMergeMeta.get(col.field)); |
| 148 | + result[index + i] = objCopy; |
| 149 | + } else { |
| 150 | + // this is the unmerged record, with no merge metadata |
| 151 | + result[index + i] = unmergedRec; |
| 152 | + } |
| 153 | + } |
144 | 154 | } |
145 | | - result = result.slice(0, index).concat(res, result.slice(index + res.length)); |
146 | 155 | }); |
147 | | - |
148 | | - |
149 | 156 | return result; |
150 | 157 | } |
151 | 158 | } |
|
0 commit comments