Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
create dimanic table
_Petr
Hi All.<br />
I want create report, which content dymanic table on based List<String[]>.<br />
I have class Dao for get data, this following:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
import java.util.ArrayList;
import java.util.List;
public class ReportDao {
public ReportDao() {
}
public List<String[]> getData() {
List<String[]> list = new ArrayList<String[]>();
list.add(new String[] {"name_1", "soname_1", "number_1"});
list.add(new String[] {"name_2", "soname_2", "number_2"});
list.add(new String[] {"name_3", "soname_3", "number_3"});
return list;
}
}
</pre>
How connect this class and table in report?<br />
<br />
Sorry for my poor english.
Find more posts tagged with
Comments
_Petr
In tutorial writen, what need use mimic javascript. I should add row in Data Set.<br />
I created Data Set and wrote following code:<br />
open:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
gsh = new Packages.com.trackstudio.app.report.birt.gantt.GanttDao();
gantt = gsh.getData();
count = 0;
</pre>
fetch:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if(count < gantt.size()){
values = gantt.get(count);
for (i=0;i!=values.length();++i) {
row["row_"+i] = values[i];
}
++count;
return true;
}
return false;
</pre>
But this don't work.
_Petr
Please, anyone help me! <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/public/style_emoticons/'>http://www.birt-exchange.org/org/forum/public/style_emoticons/</a><#EMO_DIR#>/confused.gif
mwilliams
Hi _Petr,
Are you getting any sort of error or exception when you try to preview the dataSet?
_Petr
No, no errors or exceptions. Preview - empty.<br />
For test, I used simplified code:<br />
fetch:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if(count < gantt.size()){
++count;
row["row_1"] = "test";
return true;
}
return false;
</pre>
but preview same empty.
mwilliams
_Petr,
And you defined this column, "row_1" in the dataSet?
_Petr
Another way this used java class extend ScriptedDataSetEventAdapter<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
package event;
import org.eclipse.birt.report.engine.api.script.IScriptedDataSetMetaData;
import org.eclipse.birt.report.engine.api.script.IUpdatableDataSetRow;
import org.eclipse.birt.report.engine.api.script.eventadapter.ScriptedDataSetEventAdapter;
import org.eclipse.birt.report.engine.api.script.instance.IDataSetInstance;
import org.eclipse.birt.report.engine.api.script.ScriptException;
public class DataSetEvent extends ScriptedDataSetEventAdapter {
private Integer cnt=0;
private Integer cntT=3;
@Override
public void open(IDataSetInstance dataSet) throws ScriptException {
super.open(dataSet);
}
@Override
public boolean fetch(IDataSetInstance dataSet, IUpdatableDataSetRow row) throws ScriptException {
if( cnt < cntT){
try{
row.setColumnValue("name", cnt);
row.setColumnValue("name2", "hello");
row.setColumnValue("name3", "jjj");
cnt++;
return true;
}catch (Exception e){
}
}
return false;
}
@Override
public void close(IDataSetInstance dataSet) throws ScriptException {
super.close(dataSet);
}
@Override
public boolean describe(IDataSetInstance dataSet, IScriptedDataSetMetaData metaData) throws ScriptException {
metaData.addColumn("name", String.class);
metaData.addColumn("name2", String.class);
metaData.addColumn("name3", String.class);
return true;
}
}
</pre>
But now problem how to connect the table and Data Set<br />
I think extend class TableEventAdapter <br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
package event;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.eclipse.birt.report.engine.api.script.ScriptException;
import org.eclipse.birt.report.engine.api.script.element.ITable;
import org.eclipse.birt.report.engine.api.script.eventadapter.TableEventAdapter;
import org.eclipse.birt.report.model.api.*;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
public class TableEventHandler extends TableEventAdapter {
@Override
public void onPrepare(ITable tableHandle, IReportContext reportContext) throws ScriptException {
try {
ElementFactory designFactory = reportContext.getDesignHandle().getElementFactory();
TableHandle table = (TableHandle) reportContext.getDesignHandle().findElement(tableHandle.getName());
PropertyHandle colbinds = table.getColumnBindings( );
ComputedColumn cs1 = StructureFactory.createComputedColumn( );
cs1.setName("tst");
cs1.setExpression( "dataSetRow[\"name2\"]" );
colbinds.addItem(cs1);
RowHandle mydetail = (RowHandle) table.getDetail().get(0);
CellHandle tcell = (CellHandle) mydetail.getCells().get(1);
DataItemHandle mydata = designFactory.newDataItem( null );
mydata.setResultSetColumn( "tst");
tcell.getContent().add(mydata);
RowHandle myheader = (RowHandle) table.getHeader().get(0);
CellHandle cell = (CellHandle) myheader.getCells().get( 1 );
LabelHandle mylabel = designFactory.newLabel( null );
mylabel.setText("ScriptColumn");
cell.getContent( ).add(mylabel);
} catch (Exception e) {
e.printStackTrace();
}
}
}
</pre>
but this no work!
mwilliams
_Petr,
If your dataSet already exists, you should be able to attach the table to the dataSet with:
table.setDataSet( designHandle.findDataSet( "dsName" ) );
_Petr
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="68343" data-time="1284139381" data-date="10 September 2010 - 10:23 AM"><p>
_Petr,<br />
<br />
If your dataSet already exists, you should be able to attach the table to the dataSet with:<br />
<br />
table.setDataSet( designHandle.findDataSet( "dsName" ) );<br /></p></blockquote>
But How create row in table?<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
@Override
public void onCreate(ITableInstance tableHandle, IReportContext reportContext) throws ScriptException {
try {
List<String> cols = new ArrayList<String>();
cols.add("OFFICECODE");
cols.add("CITY");
cols.add("COUNTRY");
ReportDesignHandle designHandle = reportContext.getDesignHandle();
ElementFactory designFactory = designHandle.getElementFactory();
TableHandle table = (TableHandle) reportContext.getDesignHandle().findElement(tableHandle.getName());
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( "ds" ) );
PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn cs1 = null;
for( int i=0; i < cols.size(); i++){
cs1 = StructureFactory.createComputedColumn();
cs1.setName(cols.get(i));
cs1.setExpression("dataSetRow[\"" + cols.get(i) + "\"]");
computedSet.addItem(cs1);
}
// table header
RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );
for( int i=0; i < cols.size(); i++){
LabelHandle label1 = designFactory.newLabel( (String)cols.get(i) );
label1.setText((String)cols.get(i));
CellHandle cell = (CellHandle) tableheader.getCells( ).get( i );
cell.getContent( ).add( label1 );
}
// table detail
RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
for( int i=0; i < cols.size(); i++){
CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
DataItemHandle data = designFactory.newDataItem( "data_"+(String)cols.get(i) );
data.setResultSetColumn( (String)cols.get(i));
cell.getContent( ).add( data );
}
} catch (Exception e) {
e.printStackTrace();
}
}
</pre>
this is no worked. I attached my report and Java class. May be somebody looked her.
mwilliams
Maybe this thread will help you with adding a row to your table. The default for a table that you create dynamically is 1 detail row. If you need to create another row, this will probably help.
http://www.birt-exchange.org/org/forum/index.php/topic/16624-how-to-add-a-detail-row-to-tablehandle/
_Petr
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="68773" data-time="1285341183" data-date="24 September 2010 - 08:13 AM"><p>
Maybe this thread will help you with adding a row to your table. The default for a table that you create dynamically is 1 detail row. If you need to create another row, this will probably help.<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php/topic/16624-how-to-add-a-detail-row-to-tablehandle/'>http://www.birt-exchange.org/org/forum/index.php/topic/16624-how-to-add-a-detail-row-to-tablehandle/</a><br
/></p></blockquote>
Thanks. I found other thread, where dynamic add column in table. But this done through script:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.org.eclipse.birt.report.model.api );
elementFactory = reportContext.getDesignHandle().getElementFactory()
var mytable = reportContext.getDesignHandle().findElement("tablemy");
var colbinds = mytable.getColumnBindings( );
var cs1 = StructureFactory.createComputedColumn( );
cs1.setName("tst");
cs1.setExpression( "dataSetRow[\"CITY\"]" );
colbinds.addItem( cs1 );
//second parameter is before(-1) or after(1)
mytable.insertColumn(2,-1);
//get first detail row
mydetail = mytable.getDetail( ).get( 0 );
//get first column and add detail data item
var tcell = mydetail.getCells( ).get( 1 );
var mydata = elementFactory.newDataItem( null );
mydata.setResultSetColumn( "tst");
tcell.getContent( ).add( mydata );
//get header and add label
var myheader = mytable.getHeader().get( 0 );
tcell = myheader.getCells( ).get(1);
var mylabel = elementFactory.newLabel(null);
mylabel.setText("ScriptColumn");//$NON-NLS-1$
tcell.getContent( ).add( mylabel );
</pre>
How make this with help handler table in Java?
mwilliams
Can you not use the script methods to add your rows/columns?
_Petr
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="69044" data-time="1286284429" data-date="05 October 2010 - 06:13 AM"><p>
Can you not use the script methods to add your rows/columns?<br /></p></blockquote>
Certainly. I can do it this way. But I would have got way make this through Java. Thank you for helping me.