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)
Group Handling in Table
cassy
Hi,
I created a table with information in header, content and footer. I grouped the columns in header and footer in a group. When i use java to read the information in the table, it successfully shows all the info in the content but it fails to read the group. I tried to use tableHandle method to call it but it fails.
My problem is whether there is a handler to handle the header and footer in the group and how it can be done.
I'm a newbie in birt. Please correct me if I'm wrong.
Cassy.
Find more posts tagged with
Comments
mwilliams
Hi Cassy,
What are you trying to do, exactly? Where are you trying to write this java? Explain a little more on your situation, if you can!
cassy
Hi mwilliams,<br />
<br />
Thanks for your reply. I'm actually trying to extract all the information from a .rptdesign file using java code. Every info except those which are grouped in a 'group' are not being extracted out. Below is part of the code that i used to extract the header, detail and footer of a table (the header and footer are not grouped under a group)<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>private static void extractTable(TableHandle tableHandle){
... ...
... ...
SlotHandle iTableHeader = (SlotHandle) tableHandle.getHeader();
print("Header Section:");
extractContents(iTableHeader);
SlotHandle iTableDetail = (SlotHandle) tableHandle.getDetail();
print("Detail Section:");
extractContents(iTableDetail);
SlotHandle iTableFooter = (SlotHandle) tableHandle.getFooter();
print("Footer Section:");
extractContents(iTableFooter);
}</pre>
<br />
For instance, if i want to read the header of a table, i just need to use getHeader(). So, i tried to search for similar function but ended up nothing...<br />
I really appreciate if u can explain to me if i make mistakes..<br />
Thanks!
mwilliams
In doing a little quick poking around, it looks like there is a tableGroupHandle that you will possibly need to use here instead of just the tableHandle. I could be wrong on this, but this is what it looks like to me so far.
cassy
I have same thoughts as you at first but i couldn't find any function/ method for calling the grouped footer and header so i thought of this method.<br />
Oh ya.. I forgot to mention that I 'tested' it using below methods. The result shows that the group is inside the table. So, in order to get the group, we need to 'pass through' the table first. (hope you understand what I'm trying to say)<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>... ...
for(DesignElementHandle handle : (List<DesignElementHandle>) slot.getContents()){
if(handle.getClass().equals(TableHandle.class)){
TableHandle t = (TableHandle) handle;
extractTable(t);
}
if(handle.getClass().equals(GridHandle.class)){
GridHandle grid = (GridHandle) handle;
extractGrid(grid);
}
if(handle.getClass().equals(TableGroupHandle.class)){
TableGroupHandle group = (TableGroupHandle) handle;
extractGroup(group);
}
}</pre>
<br />
<br />
This is my 'extractGroup' method if you want to have a look.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>private static void extractGroup(TableGroupHandle group) {
SlotHandle gtHeader = (SlotHandle) group.getHeader();
print("Header Section:");
extractContents(gtHeader);
SlotHandle gtFooter = (SlotHandle) group.getFooter();
print("Footer Section:");
extractContents(gtFooter);
}</pre>
mwilliams
Cassy,
Try something like this to get the group info:
TableGroupHandle tgh = (TableGroupHandle) table.getGroups().get(0);
RowHandle rh = (RowHandle) tgh.getFooter().getContents().get(0);
rh.getCells().get(0);
cassy
Mwilliams,
You mean put this under extractTable function?
Cassy
mwilliams
I think that's where I'd try it first.
cassy
Really thank u, man! I manage to extract the header and footer in the group after using your method and making some modification.
Thanks again...
Cassy
mwilliams
Cassy,
You're welcome! Let us know whenever you have questions!
anju240891
<p>here is answer how i have resolved this issue:-</p>
<p> </p>
<div>TableGroupHandle group = designFactory.newTableGroup( );</div>
<div>group.setName("MyGroup");</div>
<div>group.setKeyExpr("row[\""+cols.toUpperCase()+"\"]" ); //dataset column</div>
<div>group.setInterval("none");</div>
<div>group.setSortDirection("asc");</div>
<div> </div>
<div>
<div>table.getGroups().add( group );</div>
<div> </div>
<div>PropertyHandle computedSet = table.getColumnBindings( );</div>
<div>ComputedColumn cs5 = StructureFactory.createComputedColumn( );</div>
<div>cs5.setName("GroupTotalAmount");</div>
<div>cs5.setExpression( "Total.sum(dataSetRow[\""+cols.toUpperCase()+"\"])" );</div>
<div>cs5.setDataType("Integer");</div>
<div>cs5.setAggregateOn("MyGroup");</div>
<div>computedSet.addItem( cs5 );</div>
<div> </div>
<div> </div>
<div> </div>
<div>LabelHandle label1F = designFactory.newLabel( "" );<span> </span></div>
<div>label1F.setText("");</div>
<div>RowHandle groupHeader = designFactory.newTableRow( 3 );</div>
<div>CellHandle tcell = (CellHandle) groupHeader.getCells( ).get( 0);</div>
<div>tcell.getContent( ).add( label1F );</div>
<div>group.getHeader( ).add( groupHeader );</div>
<div> </div>
<div>//footer</div>
<div>DataItemHandle data = designFactory.newDataItem( null );</div>
<div> </div>
<div>RowHandle groupFooter = designFactory.newTableRow( 3 );</div>
<div>tcell = (CellHandle) groupFooter.getCells( ).get( 2 );</div>
<div>data = designFactory.newDataItem( null );</div>
<div>data.setResultSetColumn( cs5.getName( ) );</div>
<div>tcell.getContent( ).add( data );<span> </span></div>
<div> </div>
<div>group.getFooter( ).add( groupFooter );<span> </span></div>
<div> </div>
</div>
<p>thanks
</p>
mwilliams
Thanks for adding your solution to the discussion.