If you want to sum a particular column and have the sum show up in a page header or footer, a good solution for this is page variables. For example assume we have a table that lists quantities. We want to put the sum of these quantities per page in the header. First create a page variable named pageqty. Then select the master page and add a Variable from the auto text palette item and choose the report variable pageqty.<br />
<br />
You can populate this variable in a couple of different ways. First remember that page variables only work when the run task is separate from the render task (ie /frameset viewer mapping). Page variables are evaluated at render time not run time. Two ways of populating these values are presented below:<br />
<br />
If you are using BIRT 2.6 or greater, you can use the onPageEnd Script of the master page to calculate the value. First select the quatity data element in your table and name it qtyelement in the general properties and then select the master page and select the script tab. Enter the following script for the onPageEnd event:<br />
var qtys = this.getInstancesByElementName("qtyelement");
var tmp=0;
if( qtys != null ){
for( var i=0; i< qtys.length; i++ ){
//Instance of DataItemInstance
var qty = qtys[i];
tmp+=parseInt(qty.getValue());
}
}
reportContext.setPageVariable("pageqty",tmp);
This script looks for all instances of the qtyelement and then adds them up and puts the final value in the page variable. Thats it.<br />
<br />
If you are using BIRT 2.5 add the following scripts to the table:<br />
<br />
Table onPrepare:<br />
pageTotalQty=0;
Table Detail Row onCreate:
pageTotalQty += parseInt(this.getRowData().getColumnValue("QUANTITYORDERED"));
Table onPageBreak:
reportContext.setPageVariable("pageqty",pageTotalQty);