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 pattern format a data item using the API
david.lee
<div>Hi,</div>
<div> </div>
<div>Thank you for this great s<span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">ample!</span></div>
<div>I tried and failed to show dates in the format of "yyyy/MM/dd".</div>
<div> </div>
<div>var mydata = elementFactory.newDataItem( null );</div>
<div>mydata.setResultSetColumn( <span>mappingColumnList</span><span style="color:rgb(102,102,0);">[</span><span>i</span><span style="color:rgb(102,102,0);">]</span>);</div>
<div> </div>
<div>// if column type is "date", add format</div>
<div> if ( myColTypes
=="date" ){</div>
<div> <span> </span>var myFormat = StructureFactory.newFormatValue();</div>
<div> myFormat.setCategory("Custom");</div>
<div> <span> </span>myFormat.setPattern( "yyyy/MM/dd" );</div>
<div> }</div>
<div> </div>
<div>Can someone please let me know how to link "myFormat" to "mydata"? <br>
Thank you for help!</div>
<div> </div>
<div>David</div>
Find more posts tagged with
Comments
Matthew L.
<p>Topic split from previous thread: <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/36677-unable-to-fetch-dataset-records-in-beforeopen-function-for-dynamically-creating-computed-columns/'>http://developer.actuate.com/community/forum/index.php?/topic/36677-unable-to-fetch-dataset-records-in-beforeopen-function-for-dynamically-creating-computed-columns/</a></p>
;
<p> </p>
<p>David,</p>
<p> </p>
<p>Do you have an example report that you are currently working on that you could provide to demonstrate the issue?</p>
david.lee
<p>Hi, Matthew,</p>
<p> </p>
<p>Thank you!</p>
<p>The following is my report, it works well, but how to dynamically add date/datetime format?</p>
<p>Have a nice day!</p>
<p> </p>
<p>Best,</p>
<p>David</p>
<p> </p>
<div><br><blockquote class="ipsBlockquote">
<p>importPackage( Packages.org.eclipse.birt.report.model.api );</p>
<div> </div>
<div>var myColNames = params["colNames"].split(",");</div>
<div>var myColHeaders = params["colHeaders"].split(",");</div>
<div>var myColTypes = params["colTypes"].split(",");</div>
<div> </div>
<div>elementFactory = reportContext.getDesignHandle().getElementFactory()</div>
<div>var mytable = reportContext.getDesignHandle().findElement("myTable");</div>
<div>var colbinds = mytable.getColumnBindings( );</div>
<div>var cs1 = []; </div>
<div> </div>
<div>var i = 0;</div>
<div>while (i < myColNames.length){</div>
<div>cs1
= StructureFactory.createComputedColumn( );</div>
<div>cs1
.setName(myColNames
);</div>
<div>cs1
.setProperty("dataType", myColTypes
);</div>
<div>cs1
.setExpression("dataSetRow[\"" + myColNames[i] + "\"]");</div>
<div>colbinds.addItem( cs1
);</div>
<div> </div>
<div>mytable.insertColumn(i+1,-1);</div>
<div>mydetail = mytable.getDetail( ).get( 0 );</div>
<div> </div>
<div>var mydata = elementFactory.newDataItem( null );</div>
<div>mydata.setResultSetColumn( myColNames
);</div>
<div> </div>
<div>// to create and specify date/datetime formats to mydata</div>
<div>var myformat = StructureFactory.newFormatValue();</div>
<div>myformat.setCategory("Custom");</div>
<div> if ( myColTypes
=="date" ){</div>
<div> <span> </span>myformat.setPattern( "yyyy-MM-dd" );</div>
<div> } else if ( myColTypes
=="date-time" ){</div>
<div> <span> </span>myformat.setPattern( "yyyy-MM-dd HH:mm" );</div>
<div> }</div>
<div>// how to link "myformat" to "mydata" here?</div>
<div>// or how to do?</div>
<div> </div>
<div>var tcell = mydetail.getCells( ).get( i );</div>
<div>tcell.getContent( ).add( mydata );</div>
<div> </div>
<div>var myheader = mytable.getHeader( ).get( 0 );</div>
<div>tcell = myheader.getCells( ).get( i );</div>
<div> </div>
<div>var mylabel = elementFactory.newLabel( null );</div>
<div>mylabel.setText( myColHeaders
);//$NON-NLS-1$</div>
<div>mylabel.setProperty("textAlign", myColAligns
);</div>
<div> </div>
<div>tcell.getContent( ).add( mylabel );</div>
<div> </div>
<div>i++;</div>
<div>}</div>
</blockquote>
<p> </p>
</div>
Matthew L.
<p>Unfortunately I was unable to rebuild your example code into a working design.</p>
<p>However using one of my examples from another 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>I was able to format the data columns using the pattern in your code.</p>
<p> </p>
<p>In the attached example, lines 87-91 in the beforeFactory method, I added this block of code which formats the date column.</p>
<pre class="_prettyXprint _lang-js">
//Set Date format for Data Cell
formatValue = StructureFactory.newFormatValue();
formatValue.setPattern("yyyy-MM-dd HH:mm");
formatValue.setCategory("Custom");
data.setProperty("dateTimeFormat", formatValue);
</pre>
<p>See attached example for reference.</p>
david.lee
<p>Hi, Matthew,</p>
<p> </p>
<p>Thank you!</p>
<p>I got it, the point is data.<span>setProperty</span><span style="color:rgb(102,102,0);">(</span><span style="color:rgb(0,136,0);">"dateTimeFormat"</span><span style="color:rgb(102,102,0);">,</span><span> formatValue</span><span style="color:rgb(102,102,0);">)</span></p>