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)
How to Add Report Parameter to Grid using Design API
grather
<p>I am trying to add to a grid the value of a report parameter using the Design API</p>
<p> </p>
<p>For images and data elements</p>
<p> </p>
<p>The pattern is</p>
<p> </p>
<p>ElementFactory factory = rDesign.getElementFactory();</p>
<p> </p>
<p>newImage = factory.newImage(imgName);<br>
newImage.setURL(imgName);<br><br>
newImage.setSource(<span style="color:#008000;font-weight:bold;">"file"</span>);</p>
<p> </p>
<p> </p>
<p>or for text it is</p>
<p> </p>
<p>ElementFactory factory = rDesign.getElementFactory();<br>
TextItemHandle newTextItem = <span style="color:#000080;font-weight:bold;">null</span>;<br>
newTextItem = factory.newTextItem(secName);<br>
newTextItem.setContentType(<span style="color:#008000;font-weight:bold;">"HTML"</span>);<br>
newTextItem.setContent(text);</p>
<p> </p>
<p> </p>
<p>then I just add this to the grid</p>
<p> </p>
<p>But I am not able to figure out how to add an existing reportParameter so it can be displayed</p>
<p>
</p>
<p> </p>
<p>When I do it using the designer I end up in my XML</p>
<p>But not sure how using the designAPI</p>
<div><data id="5794"></div>
<div> <list-property name="boundDataColumns"></div>
<div> <structure></div>
<div> <property name="name">employeeSelect</property></div>
<div> <expression name="expression" type="javascript">params["employeeSelect"]</expression></div>
<div> <property name="dataType">string</property></div>
<div> </structure></div>
<div> </list-property></div>
<div> <property name="resultSetColumn">employeeSelect</property></div>
<div> </data></div>
<div> </div>
Find more posts tagged with
Comments
Matthew L.
<p>Using Data Elements can be tricky at first. However below is a simple example on how to accomplish this.</p>
<p>For an example of using Data Elements in a table, see this post: <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/24254-creating-column-dynamically/?p=132987'>http://developer.actuate.com/community/forum/index.php?/topic/24254-creating-column-dynamically/?p=132987</a></p>
;
<p> </p>
<p>To assign a Data Element a Parameter Value you must first create a Computed Column Binding:</p>
<pre class="_prettyXprint _lang-js">
var computedColumn = StructureFactory.createComputedColumn(); //Create an empty computed column structure
computedColumn.setName("MyParam"); //Set the reference name
computedColumn.setExpression("params[\"MyParameter\"]"); //Set the expression
</pre>
<p>Then you can bind the Computed Column to the Data Element and reference the Computed Column name in the Data Element's Expression (ResultSetColumn):</p>
<pre class="_prettyXprint _lang-js">
var dataItemHandle = elementFactory.newDataItem(null); //Create new data item
dataItemHandle.getColumnBindings().addItem(computedColumn); //Add column binding
dataItemHandle.setResultSetColumn("MyParam"); //Set value based on column binding reference name
</pre>
<p>Then the Data Element can be added to a Grid Cell:</p>
<pre class="_prettyXprint _lang-js">
var gridHandle = reportContext.getDesignHandle().findElement("MyGrid"); //Get grid handle
gridHandle.getCellContent(1, 1).add(dataItemHandle); //Add data element to grid cell
</pre>
<p>Below is a full code example. See attached report for a working example.</p>
<pre class="_prettyXprint _lang-js">
importPackage(Packages.org.eclipse.birt.report.model.api); //For StructureFactory
reportDesignHandle = reportContext.getDesignHandle(); //Get report design handle
elementFactory = reportDesignHandle.getElementFactory(); //Get element factory
var computedColumn = StructureFactory.createComputedColumn(); //Create an empty computed column structure
computedColumn.setName("MyParam"); //Set the reference name
computedColumn.setExpression("params[\"MyParameter\"]"); //Set the expression
var dataItemHandle = elementFactory.newDataItem(null); //Create new data item
dataItemHandle.getColumnBindings().addItem(computedColumn); //Add column binding
dataItemHandle.setResultSetColumn("MyParam"); //Set value based on column binding reference name
var gridHandle = reportContext.getDesignHandle().findElement("MyGrid"); //Get grid handle
gridHandle.getCellContent(1, 1).add(dataItemHandle); //Add data element to grid cell
</pre>
grather
<p>Thank you so much.</p>
<p>I was struggling with this.</p>
<p> </p>
<p>I solved my problem in a simpler way.</p>
<p> </p>
<p>I created a TextItemHandle</p>
<p>and set the content to <span style="color:rgb(0,128,0);font-weight:bold;">"<VALUE-OF>params[</span><span style="color:rgb(0,0,128);font-weight:bold;">\"</span><span style="color:rgb(0,128,0);font-weight:bold;">" </span>+ param + <span style="color:rgb(0,128,0);font-weight:bold;">"</span><span style="color:rgb(0,0,128);font-weight:bold;">\"</span><span style="color:rgb(0,128,0);font-weight:bold;">].value</VALUE-OF>"</span>);</p>
<p>and set the ContentType = HTML</p>
<p> </p>
<p>This worked for me.</p>
<p>I will try you solution as well. Plus it gives me anidea about how to do aggregation as well. Which is my next task</p>
<p> </p>
<p>Again thank you so much</p>