How to add data cells to group header?

mennovh
edited February 11, 2022 in Analytics #1
Hi,

I currently have a report where users can choose up to 10 columns to be displayed in a table.

I am using the following code to dynamically insert the columns and data into the detail row of the table.
var mytable = reportContext.getDesignHandle().findElement("MainTable");

for (j=1; j<10;j++) {

if (params["column_"+j]!="blank") {

//second parameter is before(-1) or after(1)
mytable.insertColumn(j,1);
//get first detail row
mydetail = mytable.getDetail().get(0);
//get first column and add detail data item
var tcell = mydetail.getCells( ).get( j );
var mydata = elementFactory.newDataItem( null );
mydata.setResultSetColumn( params["column_"+j].value);
tcell.getContent( ).add( mydata );
//get header and add label
var myheader = mytable.getHeader( ).get( 0 );
tcell = myheader.getCells( ).get( j );
var mylabel = elementFactory.newLabel( null );
mylabel.setText( params["column_"+j].displayText );//$NON-NLS-1$
tcell.getContent( ).add( mylabel );
}

This is working fine but I have now been asked to re-create the report so that the data is not but in the detail but into the 'lowest' of 4 possible groups that might have been setup.

So my question is how would i need to alter this code to insert the data cells into the groupheader row and not into the detail row of the table.

Thanks in advance.

Comments

  • mennovh
    edited July 3, 2012 #2
    Hi,

    managed to find a solution after digging around in this forum. Found a post on deleting cells from group header so re-used that code.

    Added the following to my code to determine at which 'level' in the table the data cells should be inserted:

    if (params["data_level"] =="Group1")
    {mydetail = mytable.getGroups().get(0).getHeader().get(0);}
    else if (params["data_level"] =="Group2")
    {mydetail = mytable.getGroups().get(1).getHeader().get(0);}
    else if (params["data_level"] =="Group3")
    {mydetail = mytable.getGroups().get(2).getHeader().get(0);}
    else if (params["data_level"] =="Group4")
    {mydetail = mytable.getGroups().get(3).getHeader().get(0);}
    else {mydetail = mytable.getDetail().get(0);}
  • mwilliams
    edited December 31, 1969 #3
    Glad you found a solution! Let us know whenever you have questions! :)
    Warning No formatter is installed for the format ipb