问题
I have Birt table in a report and i want to create a handler class that change the style color of the cell in the table dynamically if the cell contains the max of the column.
I try this for first step and i hooked the class to the row of the table report.
public class RowMinMax implements IRowEventHandler
{
public void onCreate(IRowInstance rowInstance, IReportContext reportContext)
{
double max=0;
IRowData rowData = rowInstance.getRowData();
double cellValue = (double) rowData.getColumnValue("nameColumn");
if(cellValue>max)
{
//change cell style
}
} ... //OTHER METHOD INTERFACE
}
I can not find a suitable method to find the object cell and set the style (es. font color red).
How can I fix this?
Thanks
回答1:
Why so complicated? You can achieve this with Javascript in the rptdesign file. No need to use a custom Java class. First, you should compute the maximum (let's call it "maxValue") using BIRT's aggregation columns - either in the DataSet itself or in the Table item definition. Next, you can define a function like this in the reports's initialize event:
function modifyStyle(cell, row) {
if (row["nameColumn"] >= row["maxValue"]) {
cell.getStyle().borderLeftWidth = "3px";
cell.getStyle().borderRightWidth = "3px";
}
}
In the cell's onCreate event, call the function:
modifyStyle(this, row);
来源:https://stackoverflow.com/questions/28415064/eclipse-birt-set-style-cell-table-dynamically-with-event-handler