1

I have a jqGrid in my page. I am giving an option to hide/show columns to the user(using columnchooser) and also he will be able to rearrange the columns using the same columnchooser option. Once the user has done the configuration he can export the grid as it is to excel.

I have managed to do everything. But only problem i am facing is the column order. My Grid's column model will have the same order as grid columns order or i have to find out the order?

If i have to find the order of columns, how can we do that?

Dinesh
  • 2,026
  • 7
  • 38
  • 60

1 Answers1

1

The key point of the solution of your problem are

  • the usage of remapColumns parameter of jqGrid which hold the information about the last permutation of the columns
  • the usage of remapColumns method of jqGrid to apply the permutation to the grid.
  • the overwriting of the default implementation of done callback of the columnChooser method

Please don't confuse the remapColumns method with the internal remapColumns parameter (the same name!!!) of jqGrid which represent array on the column indexes.

I recommend you to examine the code of the demo or this one and read the answer and another answers to the close problems referenced in the "UPDATED X" part of the answer. The demos shows how you can use remapColumns method and parameter and how to use done callback of columnChooser to save and later restore the order of columns.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Actually the ColModel of the grid is retaining the Order of the columns. So in done callback method, i wrote the necessary code to persist the data. I have used jStorage plugin to persist the preferences. – Dinesh Feb 29 '12 at 09:58
  • @Dinesh: Sorry, I didn't understood from your last comment whether the problem is already solved now or not? Can you save the information in the `localStorage`, but you can't still restore it? In the case you can look at the demos which I referenced in the `loadComplete` and look at the call of `remapColumns` method. Alternatively you can reorder the `colNames` and `colModel` items corresponds to the previously saved permutation array *before* you create the grid. It will improve the performance, but you will be unable to use `remapColumns` method and will have to implement all manually. – Oleg Feb 29 '12 at 10:35
  • The problem is in excel export functionality. While sending the data to server for excel export, i am supposed to send the order of the columns from the grid. Thats where my application failed initially. But after using done event handler and colmodel, i have figured out the solution. – Dinesh Feb 29 '12 at 10:43
  • @Dinesh: If you just need the information for *exporting to excel*. You can just enumerate the *current* `colModel` array and send the value of `name` (or `index`) properties of all non-hidden columns. The information will be enough to create the export to excel on the server. – Oleg Feb 29 '12 at 10:56