2

I've looked through the jqGrid documentation and a few other SO questions, and pretty much the only documented way to handle onSortCol is when you initialize the grid, ie:

var myGrid = $("#gridid").jqGrid({
   //...
   onSortCol: function(index, iCol, sortorder) { ... }
});

Is there a way to bind to the onSortCol event through the myGrid reference, after the grid has already been initialized?

Something like:

myGrid.onSortCol(function (index, iCol, sortorder)
   {
      //...
   }
);

Thanks!

Mike Christensen
  • 88,082
  • 50
  • 208
  • 326

1 Answers1

3

I found one solution. This appears to work well:

 myGrid.setGridParam({
     onSortCol: function(index, iCol, sortorder)
     {
         alert("Hello");
     }
 });
Mike Christensen
  • 88,082
  • 50
  • 208
  • 326
  • +1 seems like the cleanest way to do it using the jqGrid API. – Justin Ethier Jun 21 '12 at 18:32
  • 1
    Yes, it's correct way (see the same [here](http://stackoverflow.com/a/3149534/315935) for example). Alternatively you can use `jqGridSortCol` event: `myGrid.bind("jqGridSortCol", function (e, index, iCol, sortOrder]) { alert("in jqGridSortCol");} )` – Oleg Jun 21 '12 at 19:27