Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » DataSet column as flat String
DataSet column as flat String [message #519279] Mon, 08 March 2010 11:21 Go to next message
Michenaud Laurent is currently offline Michenaud LaurentFriend
Messages: 10
Registered: March 2010
Junior Member
Hi,

I have a dataset with only one column (a label).

I want to print the result like this :
label1, label2, label3, label4

possible ? can you help ?
Re: DataSet column as flat String [message #519380 is a reply to message #519279] Mon, 08 March 2010 16:36 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

You could do it with a simple crosstab.

See attached example.

Jason

<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.20"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.5.1.v20090903 Build &lt;2.5.1.v20090917-1447></property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="layoutPreference">auto layout</property>
<property name="bidiLayoutOrientation">ltr</property>
<data-sources>
<script-data-source name="Data Source" id="6"/>
</data-sources>
<data-sets>
<script-data-set name="Data Set" id="7">
<list-property name="resultSetHints">
<structure>
<property name="position">1</property>
<property name="name">col1</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">col1</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">col1</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<method name="open"><![CDATA[i=0;]]></method>
<method name="fetch"><![CDATA[if( i < 5){
fn="this is a very long text string to test col wrapping";

row["col1"] = "lablel"+i;

i++;
return true;
}else{
return false;
}]]></method>
</script-data-set>
</data-sets>
<cubes>
<tabular-cube name="Data Cube" id="52">
<property name="dimensions">
<tabular-dimension name="Group" id="53">
<property
name="defaultHierarchy">NewTabularHierarchy</property>
<property name="hierarchies">
<tabular-hierarchy name="NewTabularHierarchy"
id="54">
<property name="levels">
<tabular-level name="col1" id="55">
<property
name="dataType">string</property>
<property
name="columnName">col1</property>
</tabular-level>
</property>
</tabular-hierarchy>
</property>
</tabular-dimension>
</property>
<property name="dataSet">Data Set</property>
</tabular-cube>
</cubes>
<styles>
<style name="crosstab" id="4">
<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="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>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<property name="topMargin">1in</property>
<property name="leftMargin">1.25in</property>
<property name="bottomMargin">1in</property>
<property name="rightMargin">1.25in</property>
<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>
<extended-item extensionName="Crosstab"
extensionVersion="2.5.0" id="63">
<property name="columns">
<extended-item extensionName="CrosstabView" id="65">
<property name="views">
<extended-item extensionName="DimensionView"
id="66">
<property name="dimension">Group</property>
<property name="levels">
<extended-item
extensionName="LevelView" name="NewLevel View" id="67">
<property
name="level">Group/col1</property>
<property name="member">
<extended-item
extensionName="CrosstabCell" id="68">
<property name="content">
<data name="col1" id="69">
<property
name="resultSetColumn">col1</property>
</data>
</property>
</extended-item>
</property>
</extended-item>
</property>
</extended-item>
</property>
</extended-item>
</property>
<property name="header">
<extended-item extensionName="CrosstabCell" id="64"/>
</property>
<property name="cube">Data Cube</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">col1</property>
<expression
name="expression">dimension["Group"]["col1"]</expression >
<property name="dataType">string</property>
</structure>
</list-property>
</extended-item>
</body>
</report>


Michenaud Laurent wrote:
> Hi,
>
> I have a dataset with only one column (a label).
>
> I want to print the result like this :
> label1, label2, label3, label4
>
> possible ? can you help ?
Re: DataSet column as flat String [message #519574 is a reply to message #519279] Tue, 09 March 2010 11:09 Go to previous message
Michenaud Laurent is currently offline Michenaud LaurentFriend
Messages: 10
Registered: March 2010
Junior Member
Interesting solution but i don't want to print the values in a table.

I really want a String with comma separated values.
More one thing, i would like to limit the number of elements and if the
size is greater, add "..." at the end of the string.

Best regards
Re: DataSet column as flat String [message #519628 is a reply to message #519574] Tue, 09 March 2010 09:34 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

This can be done by doing the following:
1 - add the table to the report.
2 - set its visibility property to hide it for all formats.
3 - add oncreate script to table to initialize javascript array and var.

myarr = [];
i=0;

4 - add oncreate script for row to load the array

myarr[i] = this.getRowData().getColumnValue("col1");
i++;

5 - add a text element (make sure to set it to html) after the table to
build the string you want using the array.

<VALUE-OF>var teststr="";
if( myarr != null ){
for( j=0; j<myarr.length; j++ ){
if( teststr.length > 20 ){
teststr = teststr + "...";
break;
}
if( j == (myarr.length-1)){
teststr = teststr + myarr[j];
}else if( j == 0 ){
teststr = myarr[j];
}else{
teststr = teststr + "," + myarr[j];
}
}
}
teststr;</VALUE-OF>


See attached example.

Jason

<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.20"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.5.1.v20090903 Build &lt;2.5.1.v20090917-1447></property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="layoutPreference">auto layout</property>
<property name="bidiLayoutOrientation">ltr</property>
<data-sources>
<script-data-source name="Data Source" id="6"/>
</data-sources>
<data-sets>
<script-data-set name="Data Set" id="7">
<list-property name="resultSetHints">
<structure>
<property name="position">1</property>
<property name="name">col1</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">col1</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">col1</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<method name="open"><![CDATA[i=0;]]></method>
<method name="fetch"><![CDATA[if( i < 5){
fn="this is a very long text string to test col wrapping";

row["col1"] = "lablel"+i;

i++;
return true;
}else{
return false;
}]]></method>
</script-data-set>
</data-sets>
<cubes>
<tabular-cube name="Data Cube" id="52">
<property name="dimensions">
<tabular-dimension name="Group" id="53">
<property
name="defaultHierarchy">NewTabularHierarchy</property>
<property name="hierarchies">
<tabular-hierarchy name="NewTabularHierarchy"
id="54">
<property name="levels">
<tabular-level name="col1" id="55">
<property
name="dataType">string</property>
<property
name="columnName">col1</property>
</tabular-level>
</property>
</tabular-hierarchy>
</property>
</tabular-dimension>
</property>
<property name="dataSet">Data Set</property>
</tabular-cube>
</cubes>
<styles>
<style name="crosstab" id="4">
<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="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>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<property name="topMargin">1in</property>
<property name="leftMargin">1.25in</property>
<property name="bottomMargin">1in</property>
<property name="rightMargin">1.25in</property>
<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>
<extended-item extensionName="Crosstab"
extensionVersion="2.5.0" id="63">
<property name="columns">
<extended-item extensionName="CrosstabView" id="65">
<property name="views">
<extended-item extensionName="DimensionView"
id="66">
<property name="dimension">Group</property>
<property name="levels">
<extended-item
extensionName="LevelView" name="NewLevel View" id="67">
<property
name="level">Group/col1</property>
<property name="member">
<extended-item
extensionName="CrosstabCell" id="68">
<property name="content">
<data name="col1" id="69">
<property
name="resultSetColumn">col1</property>
</data>
</property>
</extended-item>
</property>
</extended-item>
</property>
</extended-item>
</property>
</extended-item>
</property>
<property name="header">
<extended-item extensionName="CrosstabCell" id="64"/>
</property>
<property name="cube">Data Cube</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">col1</property>
<expression
name="expression">dimension["Group"]["col1"]</expression >
<property name="dataType">string</property>
</structure>
</list-property>
</extended-item>
<table id="70">
<property name="dataSet">Data Set</property>
<list-property name="visibility">
<structure>
<property name="format">all</property>
<expression name="valueExpr"
type="javascript">true</expression>
</structure>
</list-property>
<list-property name="boundDataColumns">
<structure>
<property name="name">col1</property>
<text-property name="displayName">col1</text-property>
<expression
name="expression">dataSetRow["col1"]</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<method name="onCreate"><![CDATA[myarr = [];
i=0;]]></method>
<column id="79"/>
<header>
<row id="71">
<cell id="72">
<label id="73">
<text-property name="text">col1</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="74">
<method name="onCreate"><![CDATA[myarr[i] =
this.getRowData().getColumnValue("col1");
i++;]]></method>
<cell id="75">
<data id="76">
<property
name="resultSetColumn">col1</property>
</data>
</cell>
</row>
</detail>
<footer>
<row id="77">
<cell id="78"/>
</row>
</footer>
</table>
<text id="80">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<VALUE-OF>var
teststr="";
if( myarr != null ){
for( j=0; j<myarr.length; j++ ){
if( teststr.length > 20 ){
teststr = teststr + "...";
break;
}
if( j == (myarr.length-1)){
teststr = teststr + myarr[j];
}else if( j == 0 ){
teststr = myarr[j];
}else{
teststr = teststr + "," + myarr[j];
}
}
}
teststr;</VALUE-OF>]]></text-property>
</text>
</body>
</report>



Michenaud Laurent wrote:
> Interesting solution but i don't want to print the values in a table.
>
> I really want a String with comma separated values.
> More one thing, i would like to limit the number of elements and if the
> size is greater, add "..." at the end of the string.
>
> Best regards
Previous Topic:Hiding empty rows in a cross tab
Next Topic:Download report as file (PPT or PDF) not working
Goto Forum:
  


Current Time: Fri Apr 19 15:29:30 GMT 2024

Powered by FUDForum. Page generated in 0.01863 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top