@@ -135,32 +135,44 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent {
135135 const chipsArray = area . chipsList . toArray ( ) ;
136136 const chip = chipsArray . find ( x => x . id === dragId ) ;
137137 const isNewChip = chip === undefined ;
138- const chipIndex = chipsArray . indexOf ( event . owner ) !== - 1 ? chipsArray . indexOf ( event . owner ) : chipsArray . length ;
138+ //const chipIndex = chipsArray.indexOf(event.owner) !== -1 ? chipsArray.indexOf(event.owner) : chipsArray.length;
139+ const chipIndex = currentDim . findIndex ( x => x . fieldName === event . owner . id ) !== - 1 ?
140+ currentDim . findIndex ( x => x . fieldName === event . owner . id ) : currentDim . length ;
139141 if ( isNewChip ) {
140142 const allDims = this . grid . pivotConfiguration . rows
141143 . concat ( this . grid . pivotConfiguration . columns )
142144 . concat ( this . grid . pivotConfiguration . filters ) ;
143145 // chip moved from external collection
144- const dim = allDims . find ( x => x && x . fieldName === dragId ) ;
145- if ( ! dim ) {
146+ const dims = allDims . filter ( x => x && x . fieldName === dragId ) ;
147+ if ( dims . length === 0 ) {
146148 // you have dragged something that is not a dimension
147149 return ;
148150 }
149- dim . enabled = false ;
151+ dims . forEach ( element => {
152+ element . enabled = false ;
153+ } ) ;
154+
155+ const currentDimChild = currentDim . find ( x => x && x . fieldName === dragId ) ;
156+ if ( currentDimChild ) {
157+ currentDimChild . enabled = true ;
158+ const dragChipIndex = currentDim . indexOf ( currentDimChild ) ;
159+ currentDim . splice ( dragChipIndex , 1 ) ;
160+ currentDim . splice ( dragChipIndex > chipIndex ? chipIndex : chipIndex - 1 , 0 , currentDimChild ) ;
161+ } else {
162+ const newDim = Object . assign ( { } , dims [ 0 ] ) ;
163+ newDim . enabled = true ;
164+ currentDim . splice ( chipIndex , 0 , newDim ) ;
165+ }
150166 const isDraggedFromColumn = ! ! this . grid . pivotConfiguration . columns ?. find ( x => x && x . fieldName === dragId ) ;
151167 if ( isDraggedFromColumn ) {
152168 // columns have changed.
153169 this . grid . setupColumns ( ) ;
154170 }
155-
156- const newDim = Object . assign ( { } , dim ) ;
157- newDim . enabled = true ;
158- currentDim . splice ( chipIndex , 0 , newDim ) ;
159-
160171 } else {
161172 // chip from same collection, reordered.
162173 const newDim = currentDim . find ( x => x . fieldName === dragId ) ;
163- const dragChipIndex = chipsArray . indexOf ( event . dragChip || event . dragData . chip ) ;
174+ //const dragChipIndex = chipsArray.indexOf(event.dragChip || event.dragData.chip);
175+ const dragChipIndex = currentDim . findIndex ( x => x . fieldName === dragId ) ;
164176 currentDim . splice ( dragChipIndex , 1 ) ;
165177 currentDim . splice ( dragChipIndex > chipIndex ? chipIndex : chipIndex - 1 , 0 , newDim ) ;
166178 }
0 commit comments