The usage of data_*
attribute on cell or row is one way to save cell-specific or row-specific information. See the answer for the corresponding code example.
It seems to me that another way would be more suitable for you: the usage of beforeProcessing
to parse raw server response. Inside of beforeProcessing
you have full access to all data returned from the server. One can prepare an object with additional information as a map by rowid. So one can easy get the row-specific information by rowid later. The object with additional information one can save expanding the list of standard jqGrid parameters with new one.
For example let us the input information data about the row are extended as the following
<row id='123'>
<onHoverText>this is my foo</onHoverText>
<rowSpecificURL>http://www.google.com</rowSpecificURL>
<cell><![CDATA[Blood]]></cell>
<cell class="has_data in_progress"></cell>
...
</row>
In the case the <onHoverText>
and <rowSpecificURL>
elements contains custom row-specific information. I suggest to build the object (the map) like
{
123: {tooltip: "this is my foo", url: "http://www.google.com" }
}
which saves the custom information by rowid. One can save such map myData
as your custom jqGrid parameter myParam
using
$(this).jqGrid("setGridParam", { myParam: myData });
Later you can get the information from myParam
parameter by
var rowSpecificInformation = $(this).jqGrid("getGridParam", "myParam")[rowid];
// rowSpecificInformation.tooltip and rowSpecificInformation.url
For example the code from the demo of your previous question can be rewritten as following
$("#list").jqGrid({
url: "BradDavis2.xml",
colModel: [
{ name: "c1", width: 360, classes: 'ui-state-default',
cellattr: function (rowId, val, rawObject, cm, rdata) {
// get custom row information from custom parameter
var p = $(this).jqGrid("getGridParam", "myParam"); // this.p.myParam
// get object with additional row specific information from p[rowId]
return p != null && p[rowId] != null && p[rowId].tooltip != null ?
' title="' + p[rowId].tooltip + '"' : '';
}},
...
],
...
beforeProcessing: function (data) {
var rows = $(">rows>row", data), l = rows.length, i, item, myData = {}, $p, id, myInfo;
for (i = 0; i < l; i++) {
item = rows[i];
id = $(item).attr("id"); // get rowid
// fill custom information from every row to object
myInfo = {};
$p = $("onHoverText", item);
if ($p.length > 0) {
myInfo.tooltip = $p.text();
}
$p = $("rowSpecificURL", item);
if ($p.length > 0) {
myInfo.url = $p.text();
}
// save the object with custom information in a map by id
myData[id] = myInfo;
}
// save custom information in custom jqGrid parameter
$(this).jqGrid("setGridParam", { myParam: myData });
},
onCellSelect: function(rowid, iCol, cellcontent, e, rawObject) {
var $self = $(this),
colModel = $self.jqGrid("getGridParam", "colModel"),
myData = $self.jqGrid("getGridParam", "myParam"); // this.p.myParam
if (colModel[iCol].name === "c1" && myData != null && myData[rowid] != null && myData[rowid].url != null) {
window.open(myData[rowid].url, "_blank");
}
}
The corresponding demo you will find here. If one clicks in the cell from the first column then new browser windows with www.google.com
will be opened.