Eclipse Birt - Set style cell table dynamically with Event Handler

流过昼夜 提交于 2020-01-06 14:58:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!