In this article
When you create a Table in Reportal, you will be presented with options in the menu showing you the Table objects available. In this example, the Content object is used.
Figure 1 - The Content Object
Adding the Content Object creates a new empty column in the table. This column's cells can be populated using a script.
Figure 2 - A Table with the Column Object added via a script
In this example, a Content object is added exclusively by means of a script, so the Content object will be referenced via the script and does not need to be drag-and-dropped on the Table header section.
In this setup, two tables are required. For our example we have used a single question for rows and a Statistics object as the column header:
Figure 3 - Two Tables with a single question and a Statistics object as headers
We will now add a new Column to the top table using scripting and the Header Content object.
Adding a Content object to a Table and populating it via Scripting
var hContent : HeaderContent = new HeaderContent();
//Declaring the Header Content
var dpArray : Datapoint[] = report.TableUtils.GetColumnValues("table2",1);
//referencing the bottom table via its table ID(found in table properties), and using the column ID "1" for the column
for(var i=0;i<dpArray.Length;i++) //running through the varuious rows in the table above
{
hContent.SetCellValue(i,dpArray[i].Value);
hContent.Title = new Label(9, "English title");
//The Title of the column can be set here so please ensure the correct language code is used.
}
table.ColumnHeaders.Add(hContent); //this final line adds the column to the table
The above script results in the following:
Figure 4 - The results of the applied script
Creating a Summary of Answers
var numberOfColumns : int = 4;
var datapoints : Datapoint[];
for (var j : int = 0; j < numberOfColumns; j++)
{
var content : HeaderContent = new HeaderContent();
datapoints = report.TableUtils.GetColumnValues("nameOfSourceTable", j + 1);
log.LogDebug("h3llo");
log.LogDebug(k + " : " + datapoints.length);
for (var k = 0; k < datapoints.length; k++)
{
if (datapoints[k].Value != 0)
{
content.SetCellValue(k,(datapoints[k].Value));
content.Percent = false;
content.Title = new Label(9,j);
}
else
{
content.SetCellValue(k,null); //if answer is 0, set cell to be empty
}
}
table.ColumnHeaders.Add(content);
}