Saturday, September 21, 2013

Get Column Name and Cell Contents of jqGrid on Double Click

I recently discovered the wonderful world of jqGrid, and what a wonderful world it is.  On several applications now, I’ve taken to implementing it in some sort of fashion, to either sort data or respond to various events to dynamically load data on my applications.  Today I had an issue, I needed to get the cell value and column label for the selected cell when a user double clicked in a jqGrid row.  onSelectRow makes this pretty trivial, but I didn’t want to respond to a single click, only a double click.  All the events and data required was built into jqGrid, I just couldn’t find much of anything on the web.  Hence, I figured it out, and thought I would offer my code to those who may be in need.

Instead of using onSelectRow and determining if it was a double click, etc, just use the onDblClickRow function, which offers the parameters rowid, iRow, iCol and e (for event).  Using this data, we can still access various arrays for your jqGrid and get at the appropriate cell value…

   ondblClickRow: function(rowid, iRow, iCol, e){
      var colNames = $(this).jqGrid(“getGridParam”, “colNames”);
      var colName = colNames[iCol];
      var colVal = $(this).jqGrid(“getCell”, rowid, iCol);

And that’s all there is to it!

No comments:

Post a Comment