@@ -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