I found an answer to this question from a colleague. The BaseCellRenderer is called sequentially for each column of the output. Therefore, it will touch each cell leading up to the last column where I want to create my action link. Because of this, you can write script for each column to capture that column's value and hold it in a temporary JavaScript variable. When you render the last column, you can pull from the JavaScript variables to the data you need from the record to create the link.
In my example, I was working with ps data from Linux and I needed to capture the HOST, COMMAND and ARGUMENTS fields. In my JavaScript, I first created three global variables:
var rowHost;
var rowCommand;
var rowArguments;
Then my BaseCellRenderer definition looks something like the following:
// Use the BaseCellRenderer class to create a custom table cell renderer
var AddMonitorRenderer = TableView.BaseCellRenderer.extend({
canRender: function(cellData) {
return true;
},
// This render function only works when canRender returns "true"
render: function($td, cellData) {
switch(cellData.field.toUpperCase())
{
case "HOST":
rowHost = cellData.value;
break;
case "COMMAND":
rowCommand = cellData.value;
break;
case "ARGUMENTS":
rowArguments = cellData.value;
break;
default:
}
if(cellData.field == "Action") {
$td.html('<div align="right"><a href="#" onclick="addMonitor(\'' + escapeJSValue(rowHost) + '\',\''
+ escapeJSValue(rowCommand) + '\',\''
+ escapeJSValue(rowArguments) + '\')">Add to Monitor</a></div>');
}
else {
$td.html(cellData.value);
}
}
});
This does a couple of things:
The canRender function always returns a value of true. This way, the renderer class will fire for each column of the result set.
In the render function, I test to see which field the renderer is currently running for (HOST, COMMAND, ARGUMENTS) and then I store that column's value in the appropriate global variable.
In the final if statement, if I am in my Action column (this was a dummy value that I added to my search criteria using | eval Action = 1 ), then I display a link to my addMonitor() function. (NOTE: The escapeJSValue() function is a custom function I have in another part of my code.) If I am not in my Action column, then simply display that column's field value.
I added this cell renderer to my TableView and rendered the table and my action appears and works correctly.
... View more