@@ -860,41 +860,79 @@ export class IgxGridComponent implements OnInit, OnDestroy, AfterContentInit, Af
860
860
return totalWidth ;
861
861
}
862
862
863
+ protected _moveColumns ( from : IgxColumnComponent , to : IgxColumnComponent ) {
864
+ const list = this . columnList . toArray ( ) ;
865
+ const fi = list . indexOf ( from ) ;
866
+ const ti = list . indexOf ( to ) ;
867
+ list . splice ( ti , 0 , ...list . splice ( fi , 1 ) ) ;
868
+ const newList = this . _regenerateColumns ( list ) ;
869
+ this . columnList . reset ( newList ) ;
870
+ this . columnList . notifyOnChanges ( ) ;
871
+ }
872
+
873
+ protected _regenerateColumns ( list ?) {
874
+ if ( ! list ) {
875
+ list = this . columnList . toArray ( ) ;
876
+ }
877
+ let newList = [ ] ;
878
+ list . filter ( c => c . level === 0 ) . forEach ( p => {
879
+ newList . push ( p ) ;
880
+ if ( p . columnGroup ) {
881
+ newList = newList . concat ( p . allChildren ) ;
882
+ }
883
+ } ) ;
884
+ return newList ;
885
+ }
886
+
887
+ protected _moveChildColumns ( parent : IgxColumnComponent , from : IgxColumnComponent , to : IgxColumnComponent ) {
888
+ const buffer = parent . children . toArray ( ) ;
889
+ const fi = buffer . indexOf ( from ) ;
890
+ const ti = buffer . indexOf ( to ) ;
891
+ buffer . splice ( ti , 0 , ...buffer . splice ( fi , 1 ) ) ;
892
+ parent . children . reset ( buffer ) ;
893
+ }
894
+
863
895
public moveColumn ( column : IgxColumnComponent , dropTarget : IgxColumnComponent ) {
864
- if ( column . pinned ) {
865
- const fromIndex = this . _pinnedColumns . indexOf ( column ) ;
866
896
867
- const toIndex = dropTarget . pinned ? this . _pinnedColumns . indexOf ( dropTarget ) :
868
- this . _unpinnedColumns . indexOf ( dropTarget ) ;
897
+ if ( column . level ) {
898
+ this . _moveChildColumns ( column . parent , column , dropTarget ) ;
899
+ }
900
+ this . _moveColumns ( column , dropTarget ) ;
869
901
870
- this . _pinnedColumns . splice ( fromIndex , 1 ) ;
902
+ // if (column.pinned) {
903
+ // const fromIndex = this._pinnedColumns.indexOf(column);
871
904
872
- if ( dropTarget . pinned ) {
873
- column . pinned = true ;
874
- // this._pinnedColumns.splice(toIndex, 0, column);
875
- } else {
876
- column . pinned = false ;
877
- // this._unpinnedColumns.splice(toIndex + 1, 0, column);
878
- }
879
- } else {
880
- const fromIndex = this . _unpinnedColumns . indexOf ( column ) ;
905
+ // const toIndex = dropTarget.pinned ? this._pinnedColumns.indexOf(dropTarget) :
906
+ // this._unpinnedColumns.indexOf(dropTarget);
881
907
882
- const toIndex = dropTarget . pinned ? this . _pinnedColumns . indexOf ( dropTarget ) :
883
- this . _unpinnedColumns . indexOf ( dropTarget ) ;
908
+ // this._pinnedColumns.splice(fromIndex, 1);
884
909
885
- this . _unpinnedColumns . splice ( fromIndex , 1 ) ;
910
+ // if (dropTarget.pinned) {
911
+ // column.pinned = true;
912
+ // // this._pinnedColumns.splice(toIndex, 0, column);
913
+ // } else {
914
+ // column.pinned = false;
915
+ // // this._unpinnedColumns.splice(toIndex + 1, 0, column);
916
+ // }
917
+ // } else {
918
+ // const fromIndex = this._unpinnedColumns.indexOf(column);
886
919
887
- if ( dropTarget . pinned ) {
888
- column . pinned = true ;
889
- this . _pinnedColumns . splice ( toIndex , 0 , column ) ;
890
- } else {
891
- column . pinned = false ;
892
- this . _unpinnedColumns . splice ( toIndex , 0 , column ) ;
893
- }
894
- }
920
+ // const toIndex = dropTarget.pinned ? this._pinnedColumns.indexOf(dropTarget) :
921
+ // this._unpinnedColumns.indexOf(dropTarget);
895
922
896
- this . columnList . reset ( this . _pinnedColumns . concat ( this . _unpinnedColumns ) ) ;
897
- this . columnList . notifyOnChanges ( ) ;
923
+ // this._unpinnedColumns.splice(fromIndex, 1);
924
+
925
+ // if (dropTarget.pinned) {
926
+ // column.pinned = true;
927
+ // this._pinnedColumns.splice(toIndex, 0, column);
928
+ // } else {
929
+ // column.pinned = false;
930
+ // this._unpinnedColumns.splice(toIndex, 0, column);
931
+ // }
932
+ // }
933
+
934
+ // this.columnList.reset(this._pinnedColumns.concat(this._unpinnedColumns));
935
+ // this.columnList.notifyOnChanges();
898
936
}
899
937
900
938
public nextPage ( ) : void {
@@ -1397,9 +1435,8 @@ export class IgxGridComponent implements OnInit, OnDestroy, AfterContentInit, Af
1397
1435
1398
1436
// XXX: Deprecate index
1399
1437
1400
- collection . forEach ( ( column : IgxColumnComponent , index : number ) => {
1438
+ collection . forEach ( ( column : IgxColumnComponent ) => {
1401
1439
column . gridID = this . id ;
1402
- // column.index = index;
1403
1440
if ( ! column . width ) {
1404
1441
column . width = this . columnWidth ;
1405
1442
}
0 commit comments