how to generate dynamic columns in dynamicreports via java

Deadly 提交于 2019-12-11 16:43:30

问题


I wrote an app that gathers details about clients and generates a monthly report with Jasper Dynamic Report. until now , my report shows all fields, and some might be blank with some clients, and full in others.

I want to make a dynamic report that chooses only the non empty columns for each client. to accomplish that I have created arrays for :

aggregationSubtotalBuilder, TextColumnBuilder, ConditionalStyleBuilder, StyleBuilder,

so instead of doing this

TextColumnBuilder<Double> offLine  = col.column "OffLine","offline",type.doubleType());
TextColumnBuilder<Double> onLine   = col.column("OnLine","online",type.doubleType());

. . .

im doing this:

for (int i = 0; i < activeColumns.length; i++) 
  {
     activeColumnsForDataSource[i] = activeColumns[i];
     textColumnBuilder[i] = col.column("\"" + activeColumnsForDataSource[i] + "\"","\"" + activeColumns[i] + "\"",type.doubleType()).setTitleFixedHeight(30);
     conditionStyleBuilder[i] = stl.conditionalStyle(cnd.unEqual(textColumnBuilder[i], 0)).setFontSize(12).bold();
     styleBuilder[i] = stl.style().conditionalStyles(conditionStyleBuilder[i]).setBorder(stl.pen1Point());

     textColumnBuilder[i].setStyle(styleBuilder[i]).setHorizontalAlignment(HorizontalAlignment.CENTER);
     aggregationSubtotalBuilder[i] = sbt.sum(textColumnBuilder[i]).setLabel("סהכ" + activeColumns[i]).setLabelStyle(sumLabelStyle).setStyle(dataNameStyle);

where "activeColumns" is an array with the names of all active columns I want to add.

one of the issues I have trouble with is that I have a Date column, that should always be displayed, and it is of a string type:

TextColumnBuilder<String> dayDate  = col.column("תאריך","date",type.stringType()).setStyle(rowNamesStyle);

so I cannot add it to the TextColumnBuilder Array . how can I add it to the report?

in the build() if I do something like this

.columns(//add columns
             textColumnBuilder,dayDate)
       .columnGrid(
             textColumnBuilder,dayDate)

it will only show the last item I added , which is DayDate.

what can I do ?

Please help !

thank you.

dave.


回答1:


columns(textColumnBuilder).addColumn(dayDate)

and remove the ColumnGrid.

now its working :)



来源:https://stackoverflow.com/questions/28323565/how-to-generate-dynamic-columns-in-dynamicreports-via-java

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