Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Changing CellHandle Color Property Dynamically
shellie
I'm creating a report with a XML datasource. The XML has <value> and <valuecolor> elements. I'm trying to dynamically set the "value" elements cell color to the value of the dataSetRow["valuecolor]". I'm not having much luck. Each row is being printed out, but I don't know the syntax to add the dynamic color instead of the hard-coded "red" value. Do I need to create another ComputedColumn for the dataSetRow["valuecolor]"?
Any ideas? Thanks
cs3 = StructureFactory.createComputedColumn( );
cs3.setName("Node");
cs3.setExpression("dataSetRow["value"]");//$NON-NLS-1$
computedSet.addItem( cs3 );
RowHandle detail3 = (RowHandle) table.getDetail( ).get( 0 );
tcell = (CellHandle) detail3.getCells( ).get( 2 );
tcell.setStringProperty("color", "red");
DataItemHandle data3 = elementFactory.newDataItem( null );
data3.setResultSetColumn( cs3.getName( ) );
tcell.getContent( ).add( data3 );
Find more posts tagged with
Comments
mwilliams
Hi shellie,
What does the data "valuecolor" look like?
shellie
<valuecolor>green</valuecolor>
mwilliams
shellie,
Have you tried using the setBackgroundColor(string color) function with the valuecolor row string as the argument? The "valuecolor" value would obviously have to be one that is recognized by the setBackgroundColor function.
shellie
Thanks for your help.
I'm not understanding where to setBackground.
Here is my entire createBody method. I've put a TODO comment where I'd like to set the color of each row. Would I need to create a computedColumn for the 'valuecolor'?
private void createBody( ) throws SemanticException
{
TableHandle table = elementFactory.newTableItem( null, 4, 1, 1, 1 );
table.setProperty( IStyleModel.TEXT_ALIGN_PROP,
DesignChoiceConstants.TEXT_ALIGN_CENTER );
table.setWidth( "100%" );//$NON-NLS-1$
table.setProperty( IReportItemModel.DATA_SET_PROP, "Data Set" );//$NON-NLS-1$
PropertyHandle computedSet = table.getColumnBindings( );
cs1 = StructureFactory.createComputedColumn( );
cs1.setName("Module");
cs1.setExpression("dataSetRow["name"]");//$NON-NLS-1$
computedSet.addItem( cs1 );
cs2 = StructureFactory.createComputedColumn( );
cs2.setName("Area");
cs2.setExpression("dataSetRow["name_1"]");//$NON-NLS-1$
computedSet.addItem( cs2 );
cs3 = StructureFactory.createComputedColumn( );
cs3.setName("Node");
cs3.setExpression("dataSetRow["value"]");//$NON-NLS-1$
computedSet.addItem( cs3 );
// create header code
...
// create table details
//TODO here is where I want to set the color of each row to the 'valuecolor' element in the XML file.
DataItemHandle data = null;
// Detail
RowHandle detail = (RowHandle) table.getDetail( ).get( 0 );
tcell = (CellHandle) detail.getCells( ).get( 0 );
data = elementFactory.newDataItem( null );
data.setResultSetColumn( cs1.getName( ) );
tcell.getContent( ).add( data );
RowHandle detail2 = (RowHandle) table.getDetail( ).get( 0 );
tcell = (CellHandle) detail2.getCells( ).get( 1 );
DataItemHandle data2 = elementFactory.newDataItem( null );
data2.setResultSetColumn( cs2.getName( ) );
tcell.getContent( ).add( data2 );
RowHandle detail3 = (RowHandle) table.getDetail( ).get( 0 );
tcell = (CellHandle) detail3.getCells( ).get( 2 );
//tcell.setStringProperty("color", cs4.getValue());
//detail3.setStringProperty("color", "red");
DataItemHandle data3 = elementFactory.newDataItem( null );
data3.setResultSetColumn( cs3.getName( ) );
tcell.getContent( ).add( data3 );
reportDesignHandle.getBody( ).add( table );
}
mwilliams
shellie,
I would create the computed column for "valuecolor" like you said. Then you'll actually need to set the background color for each row in the onCreate() script method for the "value" cell rather than where you're creating the table.
In the designer, I created an XML datasource and XML dataSet and used the following script in the onCreate method of the "value" data item to change the background color:
this.getStyle().backgroundColor = row["valuecolor"];
shellie
Worked great.
Thanks!