How do you retrieve selected cell value in jqGrid?
With the code below, it displays the cell value that was last selected. How do I display the cell value of the row I just clicked on?
jQuery('#grid').click( 开发者_运维技巧function() {
var grid = jQuery('#grid);
var sel_id = grid.jqGrid('getGridParam', 'selrow');
var myCellData = grid.jqGrid('getCell', sel_id, 'source_id');
$('#selrow').html("Source ID selected:" + myCellData);
});
You code is a little strange because you use jQuery binding to click
instead of the usage of events like onCellSelect. If you use this you should use the first parameter of the click function, for example e
(jQuery('#grid').click(function(e) {...});
). The e.target
is the DOM element of the cell (<td>
) or an element inside of cell (like <a>
inside of <td>
) which the user clicked. The code $(e.target).closest("td")
will gives you the cell.
If you do decide to use onCellSelect I would recommend you to read the answer with the demo.
When setting up the grid, you can define a callback function for the onCellSelect event.
e.g:
var grid = jQuery('#grid').jqGrid( {
... default grid setup ...,
onCellSelect: function(rowid, icol, cellcontent, e) { alert(cellcontent); },
});
A list of all the jqGrid events is here: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events
精彩评论