Skip to content

Commit 8394c92

Browse files
authored
Merge pull request #10833 from IgniteUI/mkirova/fix-10818
fix(igxPivot): Move dimension instance between dimension collections …
2 parents 9bac3bc + 2eb8a68 commit 8394c92

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,26 +275,19 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
275275
.concat(this.grid.pivotConfiguration.columns)
276276
.concat(this.grid.pivotConfiguration.filters);
277277
// chip moved from external collection
278-
const dims = allDims.filter(x => x && x.memberName === dragId);
279-
if (dims.length === 0) {
278+
const dim = allDims.find(x => x && x.memberName === dragId);
279+
if (!dim) {
280280
// you have dragged something that is not a dimension
281281
return;
282282
}
283-
dims.forEach(element => {
284-
element.enabled = false;
285-
});
283+
const dimType = this.getDimensionsType(dim);
284+
285+
// Dragged chip from a different dimension to the current one.
286+
const prevDimensionCollection = this.getDimensionsByType(dimType);
287+
// delete from previous dimension collection and add to current.
288+
prevDimensionCollection.splice(prevDimensionCollection.indexOf(dim), 1);
289+
currentDim.splice(targetIndex, 0, dim);
286290

287-
const currentDimChild = currentDim.find(x => x && x.memberName === dragId);
288-
if (currentDimChild) {
289-
currentDimChild.enabled = true;
290-
const dragChipIndex = currentDim.indexOf(currentDimChild);
291-
currentDim.splice(dragChipIndex, 1);
292-
currentDim.splice(dragChipIndex > chipIndex ? targetIndex : targetIndex - 1, 0, currentDimChild);
293-
} else {
294-
const newDim = Object.assign({}, dims[0]);
295-
newDim.enabled = true;
296-
currentDim.splice(targetIndex, 0, newDim);
297-
}
298291
const isDraggedFromColumn = !!this.grid.pivotConfiguration.columns?.find(x => x && x.memberName === dragId);
299292
if (isDraggedFromColumn) {
300293
// columns have changed.
@@ -341,6 +334,12 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
341334
}
342335
}
343336

337+
protected getDimensionsType(dimension: IPivotDimension) {
338+
const isColumn = !!this.grid.pivotConfiguration.columns?.find(x => x && x.memberName === dimension.memberName);
339+
const isRow = !!this.grid.pivotConfiguration.rows?.find(x => x && x.memberName === dimension.memberName);
340+
return isColumn ? PivotDimensionType.Column : isRow ? PivotDimensionType.Row : PivotDimensionType.Filter;
341+
}
342+
344343
protected getAggregatorsForValue(value: IPivotValue): IPivotAggregator[] {
345344
const dataType = value.dataType || this.grid.resolveDataTypes(this.grid.data[0][value.member]);
346345
switch (dataType) {

0 commit comments

Comments
 (0)