I was incredibly surprised to get an Actuate question thrown my way, and a good one at that. I normally don’t get Actuate questions, so I was a little excited to try to figure this one out.
The question was “How to Change a row color after clicking a button in Actuate?”
This was not as easy as I thought it would be. My first instinct was to try to override a method for to force a color change, however I ran into a few issues. First, was IServer strips out Basic events when it renders online. So if I was to publish this report online, I would not be able to use the overridden method. Also, I would need a way to force a refresh of the page without recalling the entire report, which there doesn’t seem to be a way to do this using Actuate Basic.
The second browser scripting control is simple creates a button. What I did is I overrode the Browser Scripting Controls “BrowserCode” method to return a button with an ID that is specifically set to an easy to pass value for the search function defined above. In order to uniquely define each button, I have a global parameter that gets incremented on each BrowserCode function call and uses that in the ID. It doesn’t need to be exact, or sequential, just unique.
Figure 1. Workspace
Figure 2. Setting a Global Parameter
//Get the marker tag for the clicked on button
var childElement = document.getElementById(callingObjectID);
//Variable to hold the node witht he found background attributes to change
var foundNode = null;
//Generic counter x
//Set the parent element of the caller
var parentElement = childElement.parentNode;
//Go up the DOM tree while we have not found our target and we have not reached the root DOCUMENT element
while ((!foundNode) && (parentElement.nodeName != "#document"))
//Go through each child element in the current parent, check if it has a style element defined and a background element. If so,
//then we found our target. This will find the first element to match these conditions only, so be sure to keep other surrounding elements
//background at default, which "usually" (not always) does not include them in the output
for (x = 0; x < parentElement.childNodes.length; x++)
if ((!foundNode) && (parentElement.childNodes[x].style) && (parentElement.childNodes[x].style.backgroundColor))
foundNode = parentElement.childNodes[x];
//we went through all the child elements and did not find our result, move up the tree
parentElement = parentElement.parentNode;
//After going through the DOM tree, if we found our element, then change the background color to our predefined background color. Otherwise, set it to
alert(foundNode.id + " - " + foundNode.style.backgroundColor);
if (foundNode.style.backgroundColor == "#ffffff")
foundNode.style.backgroundColor = "#B3D9E6";
foundNode.style.backgroundColor = "#ffffff";
In the details band is where I stuck the second BrowserScripting control with the button definition. The overridden BrowserCode function looks like so:
Function BrowserCode( ) As String
BrowserCode = Super::BrowserCode( )
' Insert your code here
BrowserCode = "<input name='Submit' id='Button" & CurrentRowNum & "' type='submit' onclick='ChangeRowColor(this.id);' value='Submit' />"
CurrentRowNum = CurrentRowNum + 1
Figure 3. Set Background Color
Now the final piece of the puzzle that makes this whole thing work, be sure to set the element whose color you want to change to your default background color, in my case White. Figure 3 illustrates this. The reason this works is the browser control with the button and the text field should reside in the same DIV tag. When the function goes to the parent element, it should be the DIV tag, then search the DIV tags children and it will find the element with the background color set, which is the text field. The Text Field needs to be the first element with a background color tag also; otherwise the wrong object will change color.
Now, I publish the report to IServer and preview the results. Figure 4 shows the finished report. Now, when I click on one of the buttons, the corresponding rows color will change. This can also work if the rows text is a hyperlink. Then, you can bypass the entire search process and just use the calling objects ID.
Figure 4. Finished Report