问题
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