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
Jas_Jas
I have read almost every topic about dynamic table, but I still can't find a simple solution to do this. So, here is my problem:
I have various db tables with different columns number. I can setup birt parameter to select different db table using property binding, but I can't display it with a fix table layout.
For example:
Table1 have day/recipes number
Table2 have month/sales/lost value
Parameter: Day, Month.
If select Day, the table will have two columns and data
If select Month, the table will have three columns and data
Thank you for reviewing my topic.
Jas
Find more posts tagged with
Comments
Tubal
<blockquote class='ipsBlockquote' data-author="'Jas_Jas'" data-cid="99858" data-time="1335905656" data-date="01 May 2012 - 01:54 PM"><p>
I have read almost every topic about dynamic table, but I still can't find a simple solution to do this. So, here is my problem:<br />
<br />
I have various db tables with different columns number. I can setup birt parameter to select different db table using property binding, but I can't display it with a fix table layout. <br />
<br />
For example:<br />
<br />
Table1 have day/recipes number<br />
<br />
Table2 have month/sales/lost value<br />
<br />
Parameter: Day, Month. <br />
If select Day, the table will have two columns and data<br />
If select Month, the table will have three columns and data<br />
<br />
Thank you for reviewing my topic.<br />
<br />
Jas<br /></p></blockquote>
<br />
Build two tables, one for each dataset, and then hide (or drop) the one you don't want to use based on the parameter.
Jas_Jas
Thank you for response.
What if I have more than 10 tables? Isn't there a better way to display the data without setup a fix table? If we able to add column to table dynamically, isn't there a way to do the same thing with table?
Jas
Tubal
<blockquote class='ipsBlockquote' data-author="'Jas_Jas'" data-cid="99863" data-time="1335931992" data-date="01 May 2012 - 09:13 PM"><p>
Thank you for response.<br />
<br />
What if I have more than 10 tables? Isn't there a better way to display the data without setup a fix table? If we able to add column to table dynamically, isn't there a way to do the same thing with table?<br />
<br />
Jas<br /></p></blockquote>
<br />
<br />
Did you see this page?<br />
<a class='bbc_url' href='
http://digiassn.blogspot.com/2007/11/birt-dynamic-adding-tables-and-columns.html'>http://digiassn.blogspot.com/2007/11/birt-dynamic-adding-tables-and-columns.html</a><br
/>
<br />
With only 10 tables, it might be worth building the tables manually and using a couple of lines of code to hide them. There's not really a simple way to do it dynamically that I know of. Especially if each table will be different. <br />
<br />
Of course it's possible to insert columns dynamically, but you would also have to bind all your datasets to the new columns, name your columns, modify your widths if you need to, etc. So it's just a matter of if you want to build your tables in code, or do it with the tools already available.<br />
<br />
Here's some code I use to dynamically build some log sheets. This is in my report beforeFactory event. It might be enough to get you started if you're set on doing it dynamically:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>//get our table (we already have a table named "log" built)
dynamicTable = reportContext.getReportRunnable().designHandle.findElement("log");
//now add columns to the table until we have enough to hold all our data
//(we already have one column since the table is already created.)
// cc is a variable I created earlier in my script not shown here. It's the # of columns I want to add
for (i=1; i < cc;i++)
{
dynamicTable.insertColumn(1,i);
}
//now lets add as many blank rows as we want (we'll put them in the table footer)
footers = 15
i=0;
for (i=1; i<=footers;++i)
{
//RowOperationParameters(slotID, groupID, rowIndex)
//RowOperationParameters(3 = footer, -1 = group (-1 means no group), i-1 = where we want to put the row)
var rowparams = new RowOperationParameters(3, -1, i-1);
dynamicTable.insertRow(rowparams);
}
//now we need to populate each column with our data names
//columns is an array i created earlier in the script from my dataset not shown. It held my column name and width
i=0;
for (i=0; i < cc; i++)
{
//lets see if we have a column width, and if so, set it
if(columns[1][i] != null)
{
dynamicTable.getColumns().get(i).setProperty("width",columns[1][i] + "%");
}
//now lets stick our data name in the header, and border it
myNewRow = dynamicTable.getHeader().get(0);
tCell = myNewRow.getCells().get(i);
label = elementFactory.newLabel(columns[0][i]);
label.setText(columns[0][i]);
tCell.getContent().add(label);
tCell.setProperty( StyleHandle.BORDER_BOTTOM_COLOR_PROP, "black");
tCell.setProperty( StyleHandle.BORDER_BOTTOM_STYLE_PROP, "Solid");
tCell.setProperty( StyleHandle.BORDER_BOTTOM_WIDTH_PROP, "1pt");
tCell.setProperty( StyleHandle.PADDING_BOTTOM_PROP, "0px");
tCell.setProperty( StyleHandle.BORDER_TOP_COLOR_PROP, "black");
tCell.setProperty( StyleHandle.BORDER_TOP_STYLE_PROP, "Solid");
tCell.setProperty( StyleHandle.BORDER_TOP_WIDTH_PROP, "1pt");
tCell.setProperty( StyleHandle.BORDER_RIGHT_COLOR_PROP, "black");
tCell.setProperty( StyleHandle.BORDER_RIGHT_STYLE_PROP, "Solid");
tCell.setProperty( StyleHandle.BORDER_RIGHT_WIDTH_PROP, "1pt");
tCell.setProperty( StyleHandle.BORDER_LEFT_COLOR_PROP, "black");
tCell.setProperty( StyleHandle.BORDER_LEFT_STYLE_PROP, "Solid");
tCell.setProperty( StyleHandle.BORDER_LEFT_WIDTH_PROP, "1pt");
//now lets border all of our footers cells, and set our row height
for(j=0; j<footers;++j)
{
myFooter = dynamicTable.getFooter().get(j);
myFooter.setProperty("height",".2in");
tCell = myFooter.getCells().get(i);
tCell.setProperty( StyleHandle.BORDER_BOTTOM_COLOR_PROP, "black");
tCell.setProperty( StyleHandle.BORDER_BOTTOM_STYLE_PROP, "Solid");
tCell.setProperty( StyleHandle.BORDER_BOTTOM_WIDTH_PROP, "1pt");
tCell.setProperty( StyleHandle.BORDER_TOP_COLOR_PROP, "black");
tCell.setProperty( StyleHandle.BORDER_TOP_STYLE_PROP, "Solid");
tCell.setProperty( StyleHandle.BORDER_TOP_WIDTH_PROP, "1pt");
tCell.setProperty( StyleHandle.BORDER_RIGHT_COLOR_PROP, "black");
tCell.setProperty( StyleHandle.BORDER_RIGHT_STYLE_PROP, "Solid");
tCell.setProperty( StyleHandle.BORDER_RIGHT_WIDTH_PROP, "1pt");
tCell.setProperty( StyleHandle.BORDER_LEFT_COLOR_PROP, "black");
tCell.setProperty( StyleHandle.BORDER_LEFT_STYLE_PROP, "Solid");
tCell.setProperty( StyleHandle.BORDER_LEFT_WIDTH_PROP, "1pt");
}
}</pre>
<br />
Personally, I'd probably just build the 10 tables. If you had more than that, it would probably be worth doing it dynamically.