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)
Dynamic table creation in BIRT
Sudarsan
Hi Guys,
I have a requirement to create a table dynamically in BIRT.
In Event handler for the data set i am fecthing all the required columns for the table.
Now i need to create a table with the required columns fetched in the event handler.
Currently i am using data set to populate the columns in the table statically.
Is it possible to dynamically populalte the data set and to create a table based on that dynamically generated data set?
Thanks in advance.
Regards,
Sudarsan
Find more posts tagged with
Comments
concurrent
I've come up with nothing but clunky ways to handle this problem but I recognize that table based reporting systems aren't really designed to dynamically discover the data structure and report on it. I'd love to see a worked out example by someone who is proficient at BIRT.
mwilliams
Hi Sudarsan,
So, you won't know the names of the columns in your dataSet? It'll be that dynamic?
Maybe if you explain a scenario, I'll understand better.
srijit
Hi Williams,
We are working on a column picker. The dataset contains around 60 columns but the user only wants to see certain columns that he selects in the screen.
For this we have a handler in which we have the following information
1. List the columns that the user selected
2. A dataset that contains the 60 columns.
Now we need a way to display only these columns in the report.
In the report we need to hard code the column fields but in our scenario we need to generate these fields dynamically.
can you help us out?
Regards,
Srijit & Sudarshan
frenchGuy
Hi,<br />
<br />
You can use a java event handler in a scripted data set to do this :<br />
method <br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
public class DataSetEventHandler extends ScriptedDataSetEventAdapter {
// this hashmap will contain all my columns defined in the data set
HashMap<String, Boolean> dataSetColumns;
// wil contain a list of column name, values
ListIterator<Column> myRowsIterator;
@Override
public void open(IDataSetInstance dataSet) throws ScriptException {
// getting all the column names defined in the data set
// storing the colum names in a hashmap
for (int counter = 1; counter <= dataSet.getColumnMetaData().getColumnCount(); counter++) {
dataSetColumns.put(dataSet.getColumnMetaData().getColumnLabel(counter), true);
}
/*
Here you have to populate a list of elements (in my example, the object is called "Column" that contains a string (column name) and an Object (column value)
*/
}
@Override
public boolean fetch(IDataSetInstance dataSet, IUpdatableDataSetRow row) throws ScriptException {
if (myRowsIterator.hasNext()) {
try {
int i = 1;
for (IMyRow myRow : myRowsIterator.next()) {
// if the column name exists, I set the value for a specific column name
if (dataSetColumns.containsKey(myRow.getColumnName())) {
row.setColumnValue((String) myRow.getColumnName(), myRow.getColumnValue());
}
i++;
}
return true;
}catch (ScriptException e) {
System.out.println("Exception : Fetch : Cannot populate row\n");
e.printStackTrace();
return false;
}
}
return false;
}
</pre>
<br />
<br />
This is just a quick example of how you can get column names and set column values.<br />
You have to add the code that extracts your data from your specific data sources.<br />
<br />
I hope it helps.
_Petr
Hi, frenchGuy<br />
I have exactly the same problem. <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php/topic/20471-create-dimanic-table/'>http://www.birt-exchange.org/org/forum/index.php/topic/20471-create-dimanic-table/</a><br
/>
<br />
How do I create a table based on data from the dynamic DateSet?<br />
I have used TableEventAdapter,<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
public class TableEventHandler extends TableEventAdapter {
@Override
public void onPrepare(ITable tableHandle, IReportContext reportContext) throws ScriptException {
//that there need to write for filling the table from the database?
}
}
</pre>
srijit
Hi ,
I have tried it this way but in this case I still have to specify the names of the colums in the dataset in the rptdesign xml file. I need a way to display only these dynamically fetched column names in table section of the rptdesign file.
Is there a way to do this ?
Regards,
Sudarshan
frenchGuy
<blockquote class='ipsBlockquote' data-author="'srijit'" data-cid="68749" data-time="1285326361" data-date="24 September 2010 - 04:06 AM"><p>
I need a way to display only these dynamically fetched column names in table section of the rptdesign file.<br />
Is there a way to do this ?<br /></p></blockquote>
<br />
I'm not sure that I understand your need.<br />
The table is binded on a data set and fetchs the columns from the data set. So you need to specify the column names in the data set to get them in the table.
asasa
<blockquote class='ipsBlockquote' data-author="'frenchGuy'" data-cid="68755" data-time="1285333982" data-date="24 September 2010 - 06:13 AM"><p>
I'm not sure that I understand your need.<br />
The table is binded on a data set and fetchs the columns from the data set. So you need to specify the column names in the data set to get them in the table.<br /></p></blockquote>
<br />
Hi,<br />
please explain how to create dynamically columns in birt.
mwilliams
Take a look at this, it might help:
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1099-add-column-to-table-dynamically/
asasa
hi mwilliams,
Thanks for providing sample rptdesign. In that the column is already in the dataset but i need sample code to create dataset which consists of no columns. Based on the columns retrieve from the database, dataset should create.