Skip to content

Commit cc15982

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

File tree

1 file changed

+12
-35
lines changed

1 file changed

+12
-35
lines changed

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

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3805,19 +3805,12 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38053805
*/
38063806
protected _reorderColumns(from: IgxColumnComponent, to: IgxColumnComponent, position: DropPosition, columnCollection: any[]) {
38073807
const fromIndex = columnCollection.indexOf(from);
3808-
const childColumnsCount = from.allChildren.length;
3809-
// remove item(s) to be moved.
3810-
const fromCollection = columnCollection.splice(fromIndex, childColumnsCount + 1);
3811-
3808+
columnCollection.splice(fromIndex, 1);
38123809
let dropIndex = columnCollection.indexOf(to);
3813-
38143810
if (position === DropPosition.AfterDropTarget) {
38153811
dropIndex++;
3816-
if (to.columnGroup) {
3817-
dropIndex += to.allChildren.length;
3818-
}
38193812
}
3820-
columnCollection.splice(dropIndex, 0, ...fromCollection);
3813+
columnCollection.splice(dropIndex, 0, from);
38213814
}
38223815
/**
38233816
* @hidden
@@ -3828,7 +3821,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38283821
parent.children.reset(buffer);
38293822
}
38303823
/**
3831-
* Moves a column to the specified drop target.
3824+
* Places a column before or after the specified target column.
38323825
* @example
38333826
* ```typescript
38343827
* grid.moveColumn(compName, persDetails);
@@ -3839,6 +3832,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38393832
if (column === dropTarget) {
38403833
return;
38413834
}
3835+
38423836
let position = pos;
38433837
if (position === DropPosition.None) {
38443838
warningShown = showMessage(
@@ -3847,18 +3841,15 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38473841
warningShown);
38483842
position = DropPosition.AfterDropTarget;
38493843
}
3844+
38503845
if ((column.level !== dropTarget.level) ||
38513846
(column.topLevelParent !== dropTarget.topLevelParent)) {
38523847
return;
38533848
}
38543849

38553850
this.endEdit(true);
38563851
if (column.level) {
3857-
this._moveChildColumns(column.parent, column, dropTarget, position);
3858-
}
3859-
3860-
if (dropTarget.pinned && column.pinned) {
3861-
this._reorderColumns(column, dropTarget, position, this._pinnedColumns);
3852+
this._moveChildColumns(column.parent, column, dropTarget, pos);
38623853
}
38633854

38643855
if (dropTarget.pinned && !column.pinned) {
@@ -3875,31 +3866,17 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38753866

38763867
if (!dropTarget.pinned && column.pinned) {
38773868
column.unpin();
3878-
let list = [];
3879-
3880-
if (this.pinnedColumns.indexOf(column) === -1 && this.pinnedColumns.indexOf(dropTarget) === -1) {
3881-
list = this._unpinnedColumns;
3882-
} else {
3883-
list = this._pinnedColumns;
3884-
}
3885-
3886-
const fi = list.indexOf(column);
3887-
const ti = list.indexOf(dropTarget);
3869+
}
38883870

3889-
if (pos === DropPosition.BeforeDropTarget && fi < ti) {
3890-
position = DropPosition.BeforeDropTarget;
3891-
} else if (pos === DropPosition.AfterDropTarget && fi > ti) {
3892-
position = DropPosition.AfterDropTarget;
3893-
} else {
3894-
position = DropPosition.None;
3895-
}
3871+
if (dropTarget.pinned && column.pinned) {
3872+
this._reorderColumns(column, dropTarget, pos, this._pinnedColumns);
38963873
}
38973874

3898-
if (!dropTarget.pinned) {
3899-
this._reorderColumns(column, dropTarget, position, this._unpinnedColumns);
3875+
if (!dropTarget.pinned && !column.pinned) {
3876+
this._reorderColumns(column, dropTarget, pos, this._unpinnedColumns);
39003877
}
39013878

3902-
this._moveColumns(column, dropTarget, position);
3879+
this._moveColumns(column, dropTarget, pos);
39033880
this.notifyChanges();
39043881
if (this.hasColumnLayouts) {
39053882
this.columns.filter(x => x.columnLayout).forEach(x => x.populateVisibleIndexes());

0 commit comments

Comments
 (0)