The main solution of your problem in the following: you need include parameter, for example e
, in the callback of click
handle. The parameter has Event object type which contain target property. Alternatively you can use this
in the most cases. Having e.target
you can goes to the closest parent <tr>
element. It's id
is the value which you need:
jQuery(this).find(".jqgrow td input").click(function (e) {
var rowid = $(e.target).closest("tr").attr("id");
alert(rowid);
});
Additionally you should make some other modifications in your code to fix some bugs. The usage of
name: '', index: ''
is wrong in colModel
. You should specify any non-empty unique name. For example name: 'mycheck'
.
Next I recommend you to remove all index
properties from colModel
. If you use loadonce: true
you have to use index
properties with the same values as the corresponding name
values. If you don't specify any index
properties you will have smaller and better readable code. The corresponding values of index
properties will be copied by jqGrid internally from the corresponding name
values. In the same way you can remove properties like stype: 'text', sortable: true
which values are default values (see Default
column of the documentation)
The next problem is that you include probably HTML data in the JSON response from the server. (One can't see any formatter for customButton
for example). It's not good. In the way you can have problems if the texts of the grid contains special HTML symbols. I find better to use pure data in JSON response from the server. One can use formatters, custom formatters etc on the client side. In the case one can use autoencode: true
option of jqGrid which make HTML encoding of all texts displayed in the grid. In the way you will have more safe code which will don't allow any injection (for example no including of JavaScript code during editing of data).
Next remark: I don't recommend you to use gridComplete
. The usage of loadComplete
is better. See my old answer about the subject.
The last important remark. To handle click
events on the buttons placed inside of grid one don't need to bind separate click
handle to every button. Instead of that one can use one beforeSelectRow
or onCellSelect
callback. The answer and this one describe this. The answers use <a>
in custom formatter, but <input>
works exactly in the same way.