问题
Am new to DynamicReportBuilder and want to add a new column to list the serial number of the total rows coming from the db.
Currently, I have researched through ColumnBuilder
but, wasn't able to find a feasible solution. I have tried this for now,
ColumnBuilder serialNo = ColumnBuilder.getNew();
serialNo.setTitle("S No.");
serialNo.setWidth(60);
serialNo.setFixedWidth(true);
logger.info(count+" Total Records");//Count is the total no of rows
for (int j=1;j<count;j++) {
serialNo.setColumnProperty(j+"",String.class.getName(),j+"");
}
dynamicReportBuilder.addColumn(serialNo.build());
But the problem with this is, it is only showing the last count in the serial number row. Something like this:
S. No.
3
3
3
3
回答1:
If you like to display the row count of your datasource the variabile in jasper report is REPORT_COUNT, you can us a CustomExpression to display this as report is filled.
serialNo.setCustomExpression(new CustomExpression() {
private static final long serialVersionUID = 1L;
@Override
public Object evaluate(Map fields, Map variables, Map parameters) {
return (Integer) variables.get("REPORT_COUNT");
}
@Override
public String getClassName() {
return Integer.class.getName();
}
});
NOTE: Your current code just loops all the rows and changes the
propertyNameanddescriptionof the column, hence the result isserialNo.setColumnProperty((count-1)+"",String.class.getName(),(count-1)+"")
来源:https://stackoverflow.com/questions/38871660/how-to-create-a-serial-number-for-total-entries