views:

792

answers:

2

Is there an event in jqGrid when a user uses the column dialog to add or remove columns. If not, is there another way to track column change. I need this to persist selected columns when I show the grid on different pages.

+1  A: 

Welllll.... You're showing the dialog yourself, right? So you're already in your own code?

I'm guessing that what you really mean is "when the user clicks 'Submit'?" If so, look at afterSubmitForm.

Craig Stuntz
A: 

I think he means the column changing dialog from the jqGrid 3.6 demo.

Presently there is not an event for this, but there may still be a way. Grid method columnChooser accepts the following option in the jqGrid source:

"done" : function(perm) { if (perm) self.jqGrid("remapColumns", perm, true) },

Try providing your own version of the function (see the demo page for where to call this):

jQuery("#colch").jqGrid('columnChooser', {
   "done" : function(perm) { 
       if (perm) {
          jQuery("#colch").jqGrid("remapColumns", perm, true) 

          ( ... your code here ... )
       }
   }
});

Assuming this works, you could use the following code to figure out which columns are hidden:

var colModel = $("#mygrid").getGridParam("colModel");
for (var i = 0; i < colModel.length; i++){
    if (colModel[i].hidden) { 

        ... store away colModel.name somewhere ... 

    }
}
Justin Ethier