javascriptnested-loopsbirtbirt-deapi

Add dynamic text and data inside from datasource


I want to insert dynamic text box to a cell in table via script of the cell. I searched in documentation and SO but all I found was how to insert text to dynamic text but not the dynamic text box itself.

Is that possible, and how?

Also, is it possible to add data in this place inside the dynamic text from dataset?

EDiT

what I have tried so far: having errors when using the nested loop here: Can you help understand why it gives an error? TypeError: Cannot call method "getCells" of null The output is as expected though.

importPackage( Packages.org.eclipse.birt.report.model.api );
elementFactory = reportContext.getDesignHandle().getElementFactory()
var mytable = reportContext.getDesignHandle().findElement("tblC");


//var mydetail =  mytable.getDetail( ).get( 0);

for ( var i=1;i<23;i++){
for (var j=1;j<13;j++){
//get first detail row
mydetail =  mytable.getDetail( ).get(i);
//get first column 
var tcell = mydetail.getCells( ).get( j );

var mylabel = elementFactory.newLabel( null );
mylabel.setText( "hello" );
tcell.getContent( ).add( mylabel );
}
}


Solution

  • This is possible in the beforeFactory event of the report using the DE API.

    In my answer to Color cell according to condition I describe how to modify an existing element, but it is also possible to insert elements.

    Note that in the DE API description there is even an example how to create a new report design from scratch via script.

    The DE API is accessible from within a report design by using importPackage etc in the beforeFactory event.

    Combining these references, you should be able to do what you intend.