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)
Placing new items to the report
kosta
Hello BIRT community,<br />
<br />
I know how to add items to the rptdesign on runtime but adding them on the right place in the report is something that I want to know.<br />
In some code examples I saw something like<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>designHandle.getBody( ).add( table);</pre>
where "table" is a table object. The add function can be also invoked with second parameter as position.<br />
<br />
But how do I get the position of the current elements.<br />
Can I iterate or get as list the position of the current elements? <br />
<br />
For Example I have 4 grids and the new element should be placed before the last one means between the third and fourth. <br />
<br />
Thanks in advance.
Find more posts tagged with
Comments
johnw
Yes, you can iterate over the containers. You can also do a findElement("elementName") to get your container element, and do an add once found. But it must be a container object (Grid, Table, Cell, etc etc) and there will be a little care as what type of objects you can add as children.
kosta
Thanks for the answer johnw,
but what would be the syntax like for it?
johnw
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="
http://www.eclipse.org/birt/2005/design"
; version="3.2.22" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 2.6.1.v20100902 Build <2.6.1.v20100915-1750></property>
<property name="units">in</property>
<method name="beforeFactory"><![CDATA[var myGrid = reportContext.getDesignHandle().findElement("GridToOverride");
var cellToOverride = myGrid.getCell(1, 2);
//getContent returns a SlotHandle, which is a List of DesignElementHandles
cellToOverride.getContent().drop(0);
var newLabel = reportContext.getDesignHandle().getElementFactory().newLabel("newLabel");
newLabel.setText("I have been set by script");
cellToOverride.getContent().add(newLabel);
]]></method>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<styles>
<style name="report" id="4">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab-cell" id="6">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<grid name="GridToOverride" id="7">
<column id="8"/>
<column id="9"/>
<row id="10">
<cell id="11">
<label id="13">
<text-property name="text">I have something already set.</text-property>
</label>
</cell>
<cell id="12">
<label id="14">
<text-property name="text">I will be set to something else.</text-property>
</label>
</cell>
</row>
</grid>
</body>
</report>
kosta
Thank you johnw,<br />
<br />
I have actually expected something like:<br />
<br />
pseudocode:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
for each report elements {
if(currentElemName == 'myname') {
cellToOverride.getContent().add(newLabel);
}
if(currentElemPosition == 5) {
designHandle.getBody( ).add( table, 5)
}
}
size = global (XML tree level0) items count;
designHandle.getBody( ).add( table, max-3);
</pre>
<br />
Thanks for any suggestion.
johnw
What I posted is a full working report with what your looking for. Copy and paste the XML I posted in a empty text file and rename it to a .rptDesign file. In the beforeFactory event is the code snippet your looking for.