Skip to content

Commit 4020a9b

Browse files
authored
Merge pull request #6140 from IgniteUI/mkirova/fix-6132
fix(igxGrid): Workaround for ivy issue where ContentChildren are re-e…
2 parents ebc1f86 + ba13443 commit 4020a9b

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

projects/igniteui-angular/src/lib/grids/columns/column.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ export class IgxColumnComponent implements AfterContentInit {
571571
/* No grid/width available at initialization. `initPinning` in the grid
572572
will re-init the group (if present)
573573
*/
574+
this._unpinnedIndex = this.grid.columns.filter(x => !x.pinned).indexOf(this);
574575
this._pinned = value;
575576
this.pinnedChange.emit(this._pinned);
576577
}

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,9 +3664,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
36643664
/**
36653665
* @hidden
36663666
*/
3667-
protected _reorderPinnedColumns(from: IgxColumnComponent, to: IgxColumnComponent, position: DropPosition) {
3668-
const pinned = this._pinnedColumns;
3669-
let dropIndex = pinned.indexOf(to);
3667+
protected _reorderColumns(from: IgxColumnComponent, to: IgxColumnComponent, position: DropPosition, columnCollection: any[]) {
3668+
let dropIndex = columnCollection.indexOf(to);
36703669

36713670
if (to.columnGroup) {
36723671
dropIndex += to.allChildren.length;
@@ -3680,9 +3679,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
36803679
dropIndex++;
36813680
}
36823681

3683-
pinned.splice(dropIndex, 0, ...pinned.splice(pinned.indexOf(from), 1));
3682+
columnCollection.splice(dropIndex, 0, ...columnCollection.splice(columnCollection.indexOf(from), 1));
36843683
}
3685-
36863684
/**
36873685
* @hidden
36883686
*/
@@ -3735,18 +3733,25 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
37353733
}
37363734

37373735
if (dropTarget.pinned && column.pinned) {
3738-
this._reorderPinnedColumns(column, dropTarget, position);
3736+
this._reorderColumns(column, dropTarget, position, this._pinnedColumns);
37393737
}
37403738

37413739
if (dropTarget.pinned && !column.pinned) {
37423740
column.pin();
3743-
this._reorderPinnedColumns(column, dropTarget, position);
3741+
this._reorderColumns(column, dropTarget, position, this._pinnedColumns);
3742+
37443743
}
37453744

37463745
if (!dropTarget.pinned && column.pinned) {
37473746
column.unpin();
3747+
let list = [];
3748+
3749+
if (this.pinnedColumns.indexOf(column) === -1 && this.pinnedColumns.indexOf(dropTarget) === -1) {
3750+
list = this._unpinnedColumns;
3751+
} else {
3752+
list = this._pinnedColumns;
3753+
}
37483754

3749-
const list = this.columnList.toArray();
37503755
const fi = list.indexOf(column);
37513756
const ti = list.indexOf(dropTarget);
37523757

@@ -3759,6 +3764,10 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
37593764
}
37603765
}
37613766

3767+
if (!dropTarget.pinned) {
3768+
this._reorderColumns(column, dropTarget, position, this._unpinnedColumns);
3769+
}
3770+
37623771
this._moveColumns(column, dropTarget, position);
37633772
this.notifyChanges();
37643773
if (this.hasColumnLayouts) {
@@ -4956,7 +4965,9 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
49564965
protected reinitPinStates() {
49574966
this._pinnedColumns = (this.hasColumnGroups) ? this.columnList.filter((c) => c.pinned) :
49584967
this.columnList.filter((c) => c.pinned).sort((a, b) => this._pinnedColumns.indexOf(a) - this._pinnedColumns.indexOf(b));
4959-
this._unpinnedColumns = this.columnList.filter((c) => !c.pinned);
4968+
this._unpinnedColumns = this.hasColumnGroups ? this.columnList.filter((c) => !c.pinned) :
4969+
this.columnList.filter((c) => !c.pinned)
4970+
.sort((a, b) => this._unpinnedColumns.indexOf(a) - this._unpinnedColumns.indexOf(b));
49604971
}
49614972

49624973
/**

0 commit comments

Comments
 (0)