Good day!
I am working on a project right now and I am using JQGrid to show my data. As part of its functions, users can choose columns and make these columns as their default columns.
I used ‘columnChooser’ to let my user select for their default columns.
My problem now, how to retrieve those columns the user’s selected?
And how to set those columns as their default columns?
Can someone help me with this problem.
Thanks
Jason
After the user changes the column layout, you can get the colModel from the grid, iterate through it and push the configuration in a array of json objects which will then be sent to the server. The following code does this:
The check for “rn” and “cb” means don’t take the rownumber and checkbox columns.
UPDATE
You will need a class to represent the columns:
You also need custom model binder to deserialize the incoming list:
Register the model binder in application start:
The action in the controller that handles the list will be something like this:
Note that the order of the columns is represented by their position in the list.
You can then easily read this configuration and render the grid.
UPDATE 2
The function in your case should be called like this
But not after the call for columnChooser. You can either make another button to save changes when the user chooses to do so or handle the
doneevent from the column chooser like this: