1

How can I get the selected cell value in JQgrid?

I have looked through examples where you get the selected row id and then get the cell value based on passing the column name to 'getcell' from How to get a jqGrid selected row cells value e.g.

var grid = jQuery('#list');
var sel_id = grid.jqGrid('getGridParam', 'selrow');
var myCellData = grid.jqGrid('getCell', sel_id, 'MyColName');

Is there any way to get the cell value based on the selected cell without having to specify the column name?

Community
  • 1
  • 1
jumpercake
  • 77
  • 2
  • 7

2 Answers2

1

Instead of using onSelectRow, it is much easier to use the onCellSelect of the JQGrid for it automatically gives you the value of your selected cell.

Example Code:

onCellSelect : function(rowid, col, content, e) {
      alert(content);
    );
}

Extra Details:

  • rowid is the id of the row
  • col is the index of the cell,
  • content is the content of the cell,
  • e is the event object element where we click.

(Note that this available when we not use cell editing module and is disabled when using cell editing).

0

outisde of jqgrid make a variable like

var selectedVal;

then inside the jqgrid initialisation use the onCellSelect to populate that variable with the cells content. check here for the event http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events

Alternatively you could use that same event to store the cells informations like row_id and column index in a variable, then use the "getCell" method with the information from the row and cell variables

Lee
  • 10,496
  • 4
  • 37
  • 45