5.6.2 Band Rewinding

One complication of page-level calculation is the fact that a band can be rewound to a new page during printing. Therefore, if you leave the report as it currently is, the page total may contain an extra value from the next page. To address this, you will add logic to handle the rewinding of a band.

To “undo” the effect of rewinding, you first need to determine what the last band did before it was rewound. In the onPageBreak Handler handler, you can check if the last band was rewound, and undo the last action. For this example, declare a report-level variable in the onLoad Handler to hold the last value added to the total variables.

var lastValue = 0;

In the script for the total field, simply store the last number added to the total in the variable.

lastValue = value;

Finally, add code to the onPageBreak script to determine if rewinding occurred, and to undo its effect.

// if rewound, undo the last value total

if(event.rewound) {

   if(lastValue > 1000) {

      total1 -= lastValue;

   }

   else {

      total2 -= lastValue;

   }

}

Since you don't want to lose the last value for the next page, add another block at the end of the onPageBreak to push the lastValue to the next page's totals.

// if rewound, push last value to next page

if(event.rewound) {

   if(lastValue > 1000) {

      total1 = lastValue;

   }

   else {

      total2 = lastValue;

   }

}

<< 5.6.1 Calculate Page Total © 1996-2013 InetSoft Technology Corporation (v11.5) 6 Server-Side Features >>