Skip to content

Commit a2c15ed

Browse files
authored
Merge branch 'master' into ddincheva/selectionHGrid-master
2 parents 9c9595d + 3d5e9bf commit a2c15ed

File tree

1 file changed

+36
-50
lines changed

1 file changed

+36
-50
lines changed

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

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,6 +3850,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38503850
}
38513851

38523852
/**
3853+
* Reorder columns in the main columnList and _columns collections.
38533854
* @hidden
38543855
*/
38553856
protected _moveColumns(from: IgxColumnComponent, to: IgxColumnComponent, pos: DropPosition) {
@@ -3879,94 +3880,79 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
38793880
}
38803881

38813882
/**
3883+
* Reorders columns inside the passed column collection.
3884+
* When reordering column group collection, the collection is not flattened.
3885+
* In all other cases, the columns collection is flattened, this is why adittional calculations on the dropIndex are done.
38823886
* @hidden
38833887
*/
3884-
protected _reorderColumns(from: IgxColumnComponent, to: IgxColumnComponent, position: DropPosition, columnCollection: any[]) {
3888+
protected _reorderColumns(from: IgxColumnComponent, to: IgxColumnComponent, position: DropPosition, columnCollection: any[],
3889+
inGroup = false) {
38853890
const fromIndex = columnCollection.indexOf(from);
3886-
const childColumnsCount = from.allChildren.length;
3887-
// remove item(s) to be moved.
3888-
const fromCollection = columnCollection.splice(fromIndex, childColumnsCount + 1);
3889-
3891+
const childColumnsCount = inGroup ? 1 : from.allChildren.length + 1;
3892+
columnCollection.splice(fromIndex, childColumnsCount);
38903893
let dropIndex = columnCollection.indexOf(to);
3891-
38923894
if (position === DropPosition.AfterDropTarget) {
38933895
dropIndex++;
3894-
if (to.columnGroup) {
3896+
if (!inGroup && to.columnGroup) {
38953897
dropIndex += to.allChildren.length;
38963898
}
38973899
}
3898-
columnCollection.splice(dropIndex, 0, ...fromCollection);
3900+
columnCollection.splice(dropIndex, 0, from);
38993901
}
3902+
39003903
/**
3904+
* Reorder column group collection.
39013905
* @hidden
39023906
*/
39033907
protected _moveChildColumns(parent: IgxColumnComponent, from: IgxColumnComponent, to: IgxColumnComponent, pos: DropPosition) {
39043908
const buffer = parent.children.toArray();
3905-
this._reorderColumns(from, to, pos, buffer);
3909+
this._reorderColumns(from, to, pos, buffer, true);
39063910
parent.children.reset(buffer);
39073911
}
39083912
/**
3909-
* Moves a column to the specified drop target.
3913+
* Places a column before or after the specified target column.
39103914
* @example
39113915
* ```typescript
3912-
* grid.moveColumn(column, dropTarget);
3916+
* grid.moveColumn(column, target);
39133917
* ```
39143918
*/
3915-
public moveColumn(column: IgxColumnComponent, dropTarget: IgxColumnComponent, pos: DropPosition = DropPosition.AfterDropTarget) {
3919+
public moveColumn(column: IgxColumnComponent, target: IgxColumnComponent, pos: DropPosition = DropPosition.AfterDropTarget) {
39163920

3917-
if (column === dropTarget) {
3918-
return;
3919-
}
3920-
let position = pos;
3921-
if ((column.level !== dropTarget.level) ||
3922-
(column.topLevelParent !== dropTarget.topLevelParent)) {
3921+
if (column === target || (column.level !== target.level) ||
3922+
(column.topLevelParent !== target.topLevelParent)) {
39233923
return;
39243924
}
39253925

39263926
this.endEdit(true);
39273927
if (column.level) {
3928-
this._moveChildColumns(column.parent, column, dropTarget, position);
3928+
this._moveChildColumns(column.parent, column, target, pos);
39293929
}
39303930

3931-
if (dropTarget.pinned && column.pinned) {
3932-
this._reorderColumns(column, dropTarget, position, this._pinnedColumns);
3933-
}
3934-
3935-
if (dropTarget.pinned && !column.pinned) {
3931+
if (target.pinned && !column.pinned) {
39363932
column.pin();
3937-
if (!this.isPinningToStart) {
3938-
if (pos === DropPosition.AfterDropTarget) {
3939-
position = DropPosition.AfterDropTarget;
3940-
}
3941-
}
3942-
this._reorderColumns(column, dropTarget, position, this._pinnedColumns);
39433933
}
39443934

3945-
if (!dropTarget.pinned && column.pinned) {
3935+
if (!target.pinned && column.pinned) {
39463936
column.unpin();
3947-
let list = [];
3948-
3949-
if (this.pinnedColumns.indexOf(column) === -1 && this.pinnedColumns.indexOf(dropTarget) === -1) {
3950-
list = this._unpinnedColumns;
3951-
} else {
3952-
list = this._pinnedColumns;
3953-
}
3954-
3955-
const fi = list.indexOf(column);
3956-
const ti = list.indexOf(dropTarget);
3937+
}
39573938

3958-
if (pos === DropPosition.BeforeDropTarget && fi < ti) {
3959-
position = DropPosition.BeforeDropTarget;
3960-
} else if (pos === DropPosition.AfterDropTarget && fi > ti) {
3961-
position = DropPosition.AfterDropTarget;
3962-
}
3939+
if (target.pinned && column.pinned) {
3940+
this._reorderColumns(column, target, pos, this._pinnedColumns);
39633941
}
39643942

3965-
if (!dropTarget.pinned) {
3966-
this._reorderColumns(column, dropTarget, position, this._unpinnedColumns);
3943+
if (!target.pinned && !column.pinned) {
3944+
this._reorderColumns(column, target, pos, this._unpinnedColumns);
39673945
}
39683946

3969-
this._moveColumns(column, dropTarget, position);
3947+
this._moveColumns(column, target, pos);
3948+
this._columnsReordered(column, target);
3949+
}
3950+
3951+
/**
3952+
* Notiy changes, reset cache and populateVisibleIndexes.
3953+
* @hidden
3954+
*/
3955+
private _columnsReordered(column: IgxColumnComponent, target) {
39703956
this.notifyChanges();
39713957
if (this.hasColumnLayouts) {
39723958
this.columns.filter(x => x.columnLayout).forEach(x => x.populateVisibleIndexes());
@@ -3977,7 +3963,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
39773963

39783964
const args = {
39793965
source: column,
3980-
target: dropTarget
3966+
target: target
39813967
};
39823968

39833969
this.onColumnMovingEnd.emit(args);

0 commit comments

Comments
 (0)