Skip to content

Commit 05a68b8

Browse files
committed
fix(grid): fix reordering logic when MCH #8092
1 parent cc15982 commit 05a68b8

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,6 +3772,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
37723772
}
37733773

37743774
/**
3775+
* Reorder columns in the main columnList and _columns collections.
37753776
* @hidden
37763777
*/
37773778
protected _moveColumns(from: IgxColumnComponent, to: IgxColumnComponent, pos: DropPosition) {
@@ -3801,37 +3802,43 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38013802
}
38023803

38033804
/**
3805+
* Reorders columns inside the passed column collection.
3806+
* When reordering column group collection, the collection is not flattened.
3807+
* In all other cases, the columns collection is flattened, this is why adittional calculations on the dropIndex are done.
38043808
* @hidden
38053809
*/
3806-
protected _reorderColumns(from: IgxColumnComponent, to: IgxColumnComponent, position: DropPosition, columnCollection: any[]) {
3810+
protected _reorderColumns(from: IgxColumnComponent, to: IgxColumnComponent, position: DropPosition, columnCollection: any[],
3811+
inGroup = false) {
38073812
const fromIndex = columnCollection.indexOf(from);
3808-
columnCollection.splice(fromIndex, 1);
3813+
const childColumnsCount = inGroup ? 1 : from.allChildren.length + 1;
3814+
columnCollection.splice(fromIndex, childColumnsCount);
38093815
let dropIndex = columnCollection.indexOf(to);
38103816
if (position === DropPosition.AfterDropTarget) {
38113817
dropIndex++;
3818+
if (!inGroup && to.columnGroup) {
3819+
dropIndex += to.allChildren.length;
3820+
}
38123821
}
38133822
columnCollection.splice(dropIndex, 0, from);
38143823
}
3824+
38153825
/**
3826+
* Reorder column group collection.
38163827
* @hidden
38173828
*/
38183829
protected _moveChildColumns(parent: IgxColumnComponent, from: IgxColumnComponent, to: IgxColumnComponent, pos: DropPosition) {
38193830
const buffer = parent.children.toArray();
3820-
this._reorderColumns(from, to, pos, buffer);
3831+
this._reorderColumns(from, to, pos, buffer, true);
38213832
parent.children.reset(buffer);
38223833
}
38233834
/**
38243835
* Places a column before or after the specified target column.
38253836
* @example
38263837
* ```typescript
3827-
* grid.moveColumn(compName, persDetails);
3838+
* grid.moveColumn(column, target);
38283839
* ```
38293840
*/
3830-
public moveColumn(column: IgxColumnComponent, dropTarget: IgxColumnComponent, pos: DropPosition = DropPosition.None) {
3831-
3832-
if (column === dropTarget) {
3833-
return;
3834-
}
3841+
public moveColumn(column: IgxColumnComponent, target: IgxColumnComponent, pos: DropPosition = DropPosition.None) {
38353842

38363843
let position = pos;
38373844
if (position === DropPosition.None) {
@@ -3842,17 +3849,17 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38423849
position = DropPosition.AfterDropTarget;
38433850
}
38443851

3845-
if ((column.level !== dropTarget.level) ||
3846-
(column.topLevelParent !== dropTarget.topLevelParent)) {
3852+
if (column === target || (column.level !== target.level) ||
3853+
(column.topLevelParent !== target.topLevelParent)) {
38473854
return;
38483855
}
38493856

38503857
this.endEdit(true);
38513858
if (column.level) {
3852-
this._moveChildColumns(column.parent, column, dropTarget, pos);
3859+
this._moveChildColumns(column.parent, column, target, pos);
38533860
}
38543861

3855-
if (dropTarget.pinned && !column.pinned) {
3862+
if (target.pinned && !column.pinned) {
38563863
column.pin();
38573864
if (!this.isPinningToStart) {
38583865
if (pos === DropPosition.AfterDropTarget) {
@@ -3861,22 +3868,30 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38613868
position = DropPosition.None;
38623869
}
38633870
}
3864-
this._reorderColumns(column, dropTarget, position, this._pinnedColumns);
3871+
this._reorderColumns(column, target, position, this._pinnedColumns);
38653872
}
38663873

3867-
if (!dropTarget.pinned && column.pinned) {
3874+
if (!target.pinned && column.pinned) {
38683875
column.unpin();
38693876
}
38703877

3871-
if (dropTarget.pinned && column.pinned) {
3872-
this._reorderColumns(column, dropTarget, pos, this._pinnedColumns);
3878+
if (target.pinned && column.pinned) {
3879+
this._reorderColumns(column, target, pos, this._pinnedColumns);
38733880
}
38743881

3875-
if (!dropTarget.pinned && !column.pinned) {
3876-
this._reorderColumns(column, dropTarget, pos, this._unpinnedColumns);
3882+
if (!target.pinned && !column.pinned) {
3883+
this._reorderColumns(column, target, pos, this._unpinnedColumns);
38773884
}
38783885

3879-
this._moveColumns(column, dropTarget, pos);
3886+
this._moveColumns(column, target, pos);
3887+
this._columnsReordered(column, target);
3888+
}
3889+
3890+
/**
3891+
* Notiy changes, reset cache and populateVisibleIndexes.
3892+
* @hidden
3893+
*/
3894+
private _columnsReordered(column: IgxColumnComponent, target) {
38803895
this.notifyChanges();
38813896
if (this.hasColumnLayouts) {
38823897
this.columns.filter(x => x.columnLayout).forEach(x => x.populateVisibleIndexes());
@@ -3887,7 +3902,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38873902

38883903
const args = {
38893904
source: column,
3890-
target: dropTarget
3905+
target: target
38913906
};
38923907

38933908
this.onColumnMovingEnd.emit(args);

0 commit comments

Comments
 (0)