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)
Get datatype from data and apply format
kchaksuvej
I created dynamic report using javascript (beforefactory event)<br />
<br />
This is part of my code<br />
<br />
importPackage( Packages.org.eclipse.birt.report.model.api );<br />
<br />
reportDesignHandle = reportContext.getReportRunnable().designHandle.getDesignHandle();<br />
elementFactory = reportDesignHandle.getElementFactory()<br />
<br />
table = elementFactory.newTableItem( null, 50, 1, 1, 1 );<br />
table.setWidth( "100%" );<br />
table.setProperty( "dataSet", "Data Set" );//$NON-NLS-1$<br />
<br />
<br />
// Header<br />
<br />
columnHeaderArray = params["columnHeaderList"].value.split(",");<br />
header = table.getHeader( ).get( 0 );<br />
<br />
for (i = 0; i < columnHeaderArray.length; i++) {<br />
tcell = header.getCells( ).get( i );<br />
label = elementFactory.newLabel( null );<br />
label.setText( columnHeaderArray
);//$NON-NLS-1$ <br />
label.setStyleName("Label");<br />
tcell.getContent( ).add( label );<br />
}<br />
<br />
<br />
<br />
<br />
//Detail<br />
columnNameArray = params["columnNameList"].value.split(",");<br />
computedSet = table.getColumnBindings( );<br />
detail = table.getDetail( ).get( 0 );<br />
<br />
for (i = 0; i < columnNameArray.length; i++) {<br />
cs1 = StructureFactory.createComputedColumn( );<br />
cs1.setName("\"" + columnNameArray
+ "\"");<br />
cs1.setExpression( "dataSetRow[\"" + columnNameArray
+ "\"]");<br />
computedSet.addItem( cs1 );<br />
<br />
tcell = detail.getCells( ).get( i );<br />
data = elementFactory.newDataItem( null );<br />
data.setResultSetColumn("\"" + columnNameArray
+ "\"");<br />
<br />
/** check data type to applay correct format **/ ??????????<br />
/** ????? **/ ??????????<br />
if tcell(i) == integer then apply integer format<br />
else == decimal then apply decimal format<br />
<br />
<br />
tcell.getContent( ).add( data );<br />
<br />
<br />
I would like to check the data type of data and apply the correct format because create report.<br />
I also need to make alignment based on the data type.<br />
<br />
Anyone has and ideas or solutions<br />
<br />
Thanks
Find more posts tagged with
Comments
mwilliams
I don't know that the data will be available at this time to be able to find the type out from. Can you not tell based on the column name you get from the parameter what the type will be?
kchaksuvej
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="75319" data-time="1301589185" data-date="31 March 2011 - 09:33 AM"><p>
I don't know that the data will be available at this time to be able to find the type out from. Can you not tell based on the column name you get from the parameter what the type will be?<br /></p></blockquote>
<br />
I just know only the columns name that are pass to the report.<br />
<br />
I think I can use Birt API to get that datatype at runtime.
mwilliams
In the beforeFactory, I don't think you'll have access to data types. You can probably use event handlers to override the onCreate of each element you create in your dynamic table to find the datatype and set the format.
kchaksuvej
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="75339" data-time="1301603922" data-date="31 March 2011 - 01:38 PM"><p>
In the beforeFactory, I don't think you'll have access to data types. You can probably use event handlers to override the onCreate of each element you create in your dynamic table to find the datatype and set the format.<br /></p></blockquote>
<br />
<br />
Do you have any samples? or Any docs that will give me start to do it.<br />
<br />
I'm newbie for BIRT<br />
<br />
Thanks
mwilliams
I do not have any samples of doing this same thing. Here are some examples in a devShare post that show how to do event handling.
http://www.birt-exchange.org/org/devshare/deploying-birt-reports/1060-scripting-event-handler-samples/