1

When dragging and dropping columns changing their order, jqgrid will fire jqGridRemapColumns giving you an array of the movement. Example [0,1,5,2,3,4] the last element was moved to the third position. What I am trying to do is save these transformations between sessions so I can move the columns back to the order they were left with remapColumns which takes an array of the transformations.

The issue is when remapColumns has been called with transformations, and then more transformations are applied on top. Since jqGridRemapColumns doesn't return the array with the previous transformations only the new ones. So the saved array gets overridden and only the newest transformations are saved.

How would I combine two arrays like [0,1,5,2,3,4] (move last element to the third) and [0,2,3,4,1,5] (move the second element to the second last) to get [0,5,2,3,1,4]?

Ryan Erb
  • 828
  • 1
  • 8
  • 28

2 Answers2

1

I'd recommend you to save the names of columns instead of indexes of column. Look at the demo from the answer an an example. It should solve all problems with multiple reordering of columns.

Oleg
  • 220,925
  • 34
  • 403
  • 798
0

So what I ended up doing was sorting the second array while keeping track of the sorting movements. Then applying those movements in reverse order to the first array. This works quite well and I only have to save the array list to the database.

Ryan Erb
  • 828
  • 1
  • 8
  • 28