Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Paging with BIRT viewer (auto layout vs fixed layout)
MMirabito
All,<br />
<br />
I am wondering if anyone has experienced the following behavior with BIRT viewer. <br />
<br />
I am using an iframe for the viewer. I have a <strong class='bbc'>crosstab </strong>and when the layout preference is set to ?<strong class='bbc'>auto layout</strong>? the BIRT viewer does <strong class='bbc'>NOT </strong>have paging enabled but rather displays the entire report in one page. However, if I set the layout preference to ?<strong class='bbc'>fixed layout</strong>? then paging is enabled. <br />
<br />
Is there a special way to enable paging on crosstab when ?auto layout? is set? I need to have "auto" so that the column will auto adjust based on the size of the browser (does this make sense)?<br />
<br />
BTW forgot to mention that the crosstab is generated at runtime on the "beforeFactory" event<br />
<br />
Thanks in advance,<br />
<br />
Max
Find more posts tagged with
Comments
JasonW
Max,
You could always put in a script on the aggregation cells oncreate like:
rwc = reportContext.getGlobalVariable("rwcg");
if( rwc == null ){
rwc = 0;
}
if( rwc >5 ){
this.getStyle().pageBreakAfter = "Always";
rwc=0;
reportContext.setGlobalVariable("rwcg", rwc);
}else{
this.getStyle().pageBreakAfter = "Auto";
rwc++;
reportContext.setGlobalVariable("rwcg", rwc);
}
Jason
MMirabito
Hi Jason <br />
<br />
Thanks for the tip but I am not having much success with your suggestions. For example how did the global variable get populated (ie from what event and what object, I think it?s a row cell).<br />
<br />
Also in the designer I do not have access to the aggregation cell onCreate event and I suspect it's because the entire crosstab is being created on the fly in the beforeFactory event (but I might be wrong). Can you help me understand how I should implement your suggestion?<br />
<br />
Also when the xTab is in "fixed layout" I get paging but in "auto layout" it's gone, is this behavior by design? <br />
<br />
Thanks in advance,<br />
<br />
Max<br />
<br />
<strong class='bbc'>PS: </strong>Below is code I am using to dynamically generate the xTab as you can see nothing is in the report definition until the "beforeFactory" is executed and objects begin to get created. <br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage( Packages.org.eclipse.birt.report.model.api );
importPackage( Packages.org.eclipse.birt.report.item.crosstab.core.util);
importPackage( Packages.org.eclipse.birt.report.item.crosstab.core.de);
importPackage( Packages.org.eclipse.birt.report.item.crosstab.core);
importPackage( Packages.java.util );
importPackage( Packages.java.io );
var out = new PrintWriter( new FileWriter( "c:/log.txt", false ) );
out.println("start...");
reportContext.setPersistentGlobalVariable("title", reportContext.getParameterValue("rp_title"));
createXTab();
// *****************************************
// * Create the xTab dynamically
// *
// *****************************************
function createXTab() {
try{
var reportDesignHandle = reportContext.getReportRunnable().designHandle.getDesignHandle();
out.println(reportContext.getParameterValue("rp_xDimensions"));
out.println(reportContext.getParameterValue("rp_yDimensions"));
out.println(reportContext.getParameterValue("rp_measures"));
// Extract report parameters used in creating X, Y Diemnsions, measures, subTotal, grandTotal
var s = reportContext.getParameterValue("rp_xDimensions");
var xDimensions = s.split(",");
var s = reportContext.getParameterValue("rp_yDimensions");
var yDimensions = s.split(",");
var s = reportContext.getParameterValue("rp_measures");
var measures = s.split(",");
var subTotal = reportContext.getParameterValue("rp_subTotal");
var grandTotal = reportContext.getParameterValue("rp_grandTotal");
var elementFactory = reportDesignHandle.getElementFactory();
var cubeHandle = reportDesignHandle.getCubes().get(0);
var xtab = CrosstabExtendedItemFactory.createCrosstabReportItem(reportDesignHandle, cubeHandle, "NowCrosstab" );
reportDesignHandle.getBody().add(xtab);
reportItem = xtab.getReportItem( );
xTabHandle = reportItem;
// Create X dimensions (rows)
for (var i = 0; i < xDimensions.length; i++) {
insertDimension(xTabHandle, cubeHandle, ICrosstabConstants.ROW_AXIS_TYPE, xDimensions[i], i, elementFactory, "xRowDimension");
}
// Create X dimensions (columns)
for (var i = 0; i < yDimensions.length; i++) {
insertDimension(xTabHandle, cubeHandle, ICrosstabConstants.COLUMN_AXIS_TYPE, yDimensions[i], i, elementFactory, "xColDimension");
}
// Create measures
for (var i = 0; i < measures.length; i++) {
insertMeasure(xTabHandle, cubeHandle, measures[i], i, elementFactory);
}
// Create subtotals
if (subTotal.toLowerCase() == "y") {
for (var i = 0; i < (xDimensions.length - 1); i++) {
insertSubTotal(xTabHandle, cubeHandle, elementFactory, i, xDimensions[i], measures.length);
}
}
if (grandTotal.toLowerCase() == "y") insertGrandTotal(xTabHandle, elementFactory, ICrosstabConstants.ROW_AXIS_TYPE, measures.length)
out.println("end...");
}
catch(e){
out.println(e);
}
out.close();
}
// *****************************************
// * Create xTab dimensions for rows
// * (X - ROW_AXIS_TYPE) and columns (Y - COLUMN_AXIS_TYPE)
// *
// * dvh = DimensionViewHandle
// * deh = DesignElementHandle
// *
// *****************************************
function insertDimension(xTabHandle, cubeHandle, dimensionType, dimensionName, order, elementFactory, style) {
out.println("Begin insertDimension...");
var dimension = cubeHandle.getDimension(dimensionName);
var level = dimension.getDefaultHierarchy().getLevel(0);
var dvh = xTabHandle.insertDimension(dimension, dimensionType, order);
var levelViewHandle = dvh.insertLevel(level, order);
var cellHandle = levelViewHandle.getCell();
var deh = xTabHandle.getModelHandle();
var bindingColumn = StructureFactory.newComputedColumn(deh, level.getName());
var bindingHandle = deh.addColumnBinding(bindingColumn,false);
bindingColumn.setDataType(level.getDataType());
var exp = "dimension['" + dimension.getName()+"']['"+level.getName()+"']";
out.println("exp: " +exp);
bindingColumn.setExpression( exp);
var dataHandle = elementFactory.newDataItem(level.getName());
dataHandle.setResultSetColumn(bindingHandle.getName());
dataHandle.setProperty("style", style);
cellHandle.addContent(dataHandle);
out.println("End insertDimension...");
}
// *****************************************
// * Insert measure
// *
// * mvh = MeasureViewHandle
// *****************************************
function insertMeasure(xTabHandle, cubeHandle, measureName, order, elementFactory) {
out.println("Begin insertMeasure...");
var measure = cubeHandle.getMeasure(measureName);
var mvh = xTabHandle.insertMeasure(measure, order);
mvh.getCell().getContents().get(0).setProperty("style", "xValues");
mvh.addHeader( );
var label = elementFactory.newLabel(null);
label.setText(measure.getDisplayName());
label.setProperty("style", "xMeasureHeader");
mvh.getHeader().addContent(label);
out.println("End insertMeasure...");
}
// *****************************************
// * Insert subTotal
// *
// * dvh = DimensionViewHandle
// * mvh = MeasureViewHandle
// * cch = CrosstabCellHandle
// * deh = DesignElementHandle
// *****************************************
function insertSubTotal(xTabHandle, cubeHandle, elementFactory, index, dimensionName, measureCount) {
out.println("Begin insertSubtTotal...");
var dvh = xTabHandle.getDimension( ICrosstabConstants.ROW_AXIS_TYPE, index);
var levelViewHandle = dvh.getLevel(0);
var measureList = new ArrayList();
var functionList = new ArrayList();
var mvh = xTabHandle.getMeasure(0);
measureList.add(mvh);
functionList.add("SUM");
var cch = levelViewHandle.addSubTotal(measureList, functionList);
// Create computed column for the subtotal label
var dimension = cubeHandle.getDimension(dimensionName);
var level = dimension.getDefaultHierarchy().getLevel(0);
var deh = xTabHandle.getModelHandle();
var bindingColumn = StructureFactory.newComputedColumn(deh, level.getName());
var bindingHandle = deh.addColumnBinding(bindingColumn,false);
bindingColumn.setDataType("String");
var exp = "'(' + dimension['" + dimension.getName()+"']['"+level.getName()+"'] + ') Subtotal'";
out.println("exp: " +exp);
bindingColumn.setExpression( exp);
var dataHandle = elementFactory.newDataItem(level.getName());
dataHandle.setResultSetColumn(bindingHandle.getName());
dataHandle.setProperty("style", "xSubTotalsLabel");
cch.addContent(dataHandle);
// Set the CCS style
for (var i = 0; i < measureCount; i++) {
var mvh = xTabHandle.getMeasure(i);
var actualdata = mvh.getAggregationCell(index).getContents().get(0);
actualdata.setProperty("style", "xSubTotals-" + index);
}
out.println("End insertSubtTotal...");
}
// *****************************************
// * Insert grandTotal
// *
// * dvh = DimensionViewHandle
// * mvh = MeasureViewHandle
// * cch = CrosstabCellHandle
// *****************************************
function insertGrandTotal(xTabHandle, elementFactory, dimensionType, measureCount) {
out.println("Begin insert GrandTotal...");
var label = elementFactory.newLabel( null );
label.setText("Grand Total");
label.setProperty("style", "xGrandTotalLabel");
var cch = xTabHandle.addGrandTotal(dimensionType);
cch.addContent( label );
if (dimensionType == ICrosstabConstants.ROW_AXIS_TYPE) {
for (i = 0; i < measureCount; i++) {
var mvh = xTabHandle.getMeasure(i)
var x = mvh.getAggregationCount() - 1
var actualdata = mvh.getAggregationCell(x).getContents().get(0);
actualdata.setProperty("style", "xGrandTotal");
}
}
// WARNING Currently not working properly
else if (dimensionType == ICrosstabConstants.COLUMN_AXIS_TYPE) {
out.println(dimensionType);
for (i = 0; i < measureCount; i++) {
var dvh = xTabHandle.getMeasure(1)
var actualdata = dvh.getAggregationCell(0).getContents().get(0);
actualdata.setProperty("style", "xGrandTotal");
}
}
out.println("End insertGrandTotal...");
}
</pre>
JasonW
You can always add the script using script:
oncreatescript = "rwc = reportContext.getGlobalVariable(\"rwcg\");"+
"if( rwc == null ){"+
"rwc = 0;"+
"}"+
"if( rwc >4 ){"+
"this.getStyle().pageBreakAfter = \"Always\";"+
"rwc=0;"+
"reportContext.setGlobalVariable(\"rwcg\", rwc);"+
"}else{"+
"this.getStyle().pageBreakAfter = \"Auto\";"+
"rwc++;"+
"reportContext.setGlobalVariable(\"rwcg\", rwc);"+
"}";
dataHandle.setOnCreate( oncreatescript );
If you are wanting to count this on the innermost dimension you will need to change your code a bit to only add the script on the last insertDimension. The dataHandle is here:
var dataHandle = elementFactory.newDataItem(level.getName()); dataHandle.setResultSetColumn(bindingHandle.getName()); dataHandle.setProperty("style", style); cellHandle.addContent(dataHandle);
Jason
MMirabito
Hi Jason,<br />
<br />
Thanks for the explanation it's begging to make sense. As I am implementing it I noticed that when a page break happens the dimension labels are not carried over to the next page. for example notice below how "Type 1" is on the first page but not on the second until an new dimension break appear ?Type 2?s. Is there a way to tell BIRT that on any new page always repeat the dimension names for all selected dimension. I was looking at the onPageBreak but it does not look like it?s working for me. <br />
<br />
Thanks again,<br />
<br />
Max<br />
<br />
<span style='font-family: Courier New'><br />
----page 1<br />
<strong class='bbc'><span style='color: #0000FF'>Type 1</span></strong> 1996 CA 1,258<br />
1996 GA 4,258<br />
1996 FL 4,258<br />
....<br />
--page 2<br />
1996 KY 1,258<br />
1996 MS 4,258<br />
<strong class='bbc'><span style='color: #0000FF'>Type 2</span></strong>1996 CA 258<br />
1996 GA 58<br />
1996 FL 68<br />
<strong class='bbc'><span style='color: #0000FF'>Type 3</span></strong>1996 CA 7,258<br />
1996 GA 3,258<br />
1996 FL 6,258<br />
....<br />
<br />
</span>
JasonW
The only way I know to do this is to add a data item to the intermost cell on the row header that points to the outer dimension data value ie data["COUNTRY"]; So you would have the label for the outer dimension and the one for the inner dimension in the same cell.
Jason