First you must choose the best callback that suits your requirements. This will usually be onSelectRow
, but in some other situations other callbacks like onCellSelect
, beforeSelectRow
or ondblClickRow
are better suited.
In the callback, you will get rowid
(line id
or <tr>
) as the first parameter. You can use getCell
, getRowData
or getLocalRow
to get the contents of some cell. for instance
onSelectRow: function (id) {
or
onSelectRow: function (id) { var localRowData = $(this).jqGrid('getLocalRow'); alert(localRowData.userCode); }
The latter method is best if jqGrid has local data (you use datatype: 'local'
or a remote data type, for example datatype: 'json'
combined with loadonce: true
).
UPDATED . After some posts in the comments and updating the text of your question, I see that you are using jqSuite for ASP.NET WebForms or some other commercial jqGrid-based product instead of the free, open-source jqGrid JavaScript library. I do not use jqSuite and do not know how JavaScript callbacks should be implemented in jqSuite.
What can I suggest you use the new jqGrid 4.3.2 function: jQuery as events . What you can do is type code
var $grid = jQuery("#<%= ModifyAccountUserDetailsjqGrid.ClientID %>"); $grid.bind("jqGridSelectRow", function (id) { var userCode = $(this).jqGrid('getCell', 'userCode'); alert(userCode); });
or
var $grid = jQuery("#<%= ModifyAccountUserDetailsjqGrid.ClientID %>"); $grid.bind("jqGridSelectRow", function (id) { var localRowData = $(this).jqGrid('getLocalRow'); alert(localRowData.userCode); });
An event handler for an event of the type "jqGridSelectRow" can be defined before or after creating the grid (but after creating the <table>
element with id
equal to <%= ModifyAccountUserDetailsjqGrid.ClientID %>
). In addition, if necessary, you can define more as one handler. It is very practical that you want to implement a project of some common actions for all grids.