Home
Analytics
beforeFactory: get column names from odadataset
baj09
<p>Hi, </p><p>I want to create a table with variable columns. So far I know that I have to use the beforeFactory and know how to add columns to a table.</p><p> </p><p>Now I need to access a data set and extract the columns and their names to populate the output table. </p><p>The debugger tells me I have a org.eclipse.birt.report.model.api.OdaDataSetHandle, which I get from:</p><p> </p><div><div><div>var dataTable = reportContext.getDesignHandle().findDataSet(sourceTable);</div></div></div><div> </div><div>Now, how do I get the column names from that???</div><div> </div><div>Any hint is appreciated...</div><div> </div><div>Thanks,</div><div> </div><div>Bernd</div>
Find more posts tagged with
Comments
bgbaird
<p>Bernd, are the data points that make up the columns always the same data points, or are they dynamic? </p><p> </p><p>For example, if the generated resultset has columns "A", "B", "C", "D", and "E",</p><p> </p><p>Do we always display all five, or do we display B, D, and E in some cases, and A, C, and D in others?</p><p>Do we change the column headings?</p><p>Are the column headings you want in the available resultset?</p><p> </p><p>Brian</p>
baj09
<p>I am using KNIME in conjunction with BIRT. And it happens that the data structure can change. Thus, my problem is that the columns actually change, i.e. column names and number of columns. I always want to display all columns. The column headings can be the column names coming from the data table.</p><p> </p><p>B</p>
baj09
<p>I got a bit further:</p><p> </p><div>var colList = this.getDataSet("odaTableName").getCachedResultSetColumns();</div><div>var colNum = colList.size();</div><div> </div><div>lets me iterate through the data set:</div><div> </div><div><div>itr= colList.iterator();</div><div>while(itr.hasNext())</div><div>{</div><div><div> col = itr.next();</div><div> colname = col.getName();</div><div>}</div></div></div><div> </div><div>Now i just need figure out how to create the entries for the new columns.... Though I thought I already got this working I am running into problems... but I guess I just need some more searching...</div><div> </div><div>Thanks for the help... I will post the final solution here later</div><div> </div><div>B</div>
baj09
<p>Here is a working solution... It still misses copying the styles though... Can someone please help out here?</p><p> </p><p>Thanks,</p><p> </p><p>Bernd</p><pre class="_prettyXprint _lang-js">importPackage( Packages.org.eclipse.birt.report.model.api);elementFactory = reportContext.getDesignHandle().getElementFactory()var targetTable="table name inside report";var sourceTable="name of data set"var colList = this.getDataSet(sourceTable).getCachedResultSetColumns();var colNum = colList.size();var mytable = reportContext.getDesignHandle().findElement(targetTable);try{itr= colList.iterator();colNr = 0;while(itr.hasNext()){ col = itr.next(); colname = col.getName(); // skip column from sourceTable if(colname.equals("Row ID")){continue;} // the first column should be just overwritten // this way we can define the format in the layout // unfortunately I still don't know how to do that one... if(colNr == 0){ }else{ // insert column to the right (1) mytable.insertColumn(colNr,1); datacell = mytable.getDetail().get(0).getCells().get(colNr ); var newdata = elementFactory.newDataItem( colname ); newdata.setResultSetColumn( colname ); datacell.getContent().add(newdata); var myHeader = mytable.getHeader().get(0).getCells().get(colNr); var newlabel = elementFactory.newLabel( null ); newlabel.setText( colname ); myHeader.getContent().add(newlabel); } colNr ++;}}catch(err){}</pre>