I am trying to add a button inside a jqGrid column and to assign it an action related to an element of the grid. Here is my grid definition (I will only concentrate on things important for the question)
$("#dashboard").jqGrid({
url: wsBaseUrl + 'xxxxxxxx',
colNames: ['col1', 'col2', 'col3', 'Actions'],
colModel: [
{ name: 'col1', index: 'col1', formatter: statusFormatter },
{ name: 'col2', index: 'col2', formatter: statusFormatter },
{ name: 'col3', index: 'col3', formatter: statusFormatter },
{ name: 'act', index: 'act', width: 46, sortable: false, search: false,
formatter: function () {
var cnt = "<a class='pc_link' href='#'>Perimeter Change list</a>" +
"<a class='nopc_Link' href='#'>NO perimeter change </a>";
return cnt;
}}
],
jsonReader: {
id: "elementID"
},
pager: $('#dashboard_pager'),
// ... other params omitted for brevity
gridComplete: function () {
$(".pc_Link").button({
icons: { primary: "ui-icon-folder-open" }, text: false
});
$(".nopc_Link").button({
icons: { primary: "ui-icon-star" }, text: false
});
},
subGrid: true,
// ... other params omitted for brevity
});
As you can see I have a column in my colModel definition that act as an Action Column: that is, I create two hyperlinks in this column that shall be binded to a click event and react accordingly.
After that I have a gridComplete() event where I plan to bind the click event.
What I need is a way to set the rel attribute of the hyperlink with the value of the current rowObject ID so I can retrieve it when making the call. Like in the following example:
<a class='pc_link' href='#' rel='123'>Perimeter Change list</a>
Is there a way to obtain this?
thanks for helping!
the formatter function accepts a parameter representing the row data (rowObject).
see custom formatter.