如何为总条目创建序列号? [英] How to create a Serial Number for total entries?
问题描述
是 DynamicReportBuilder
的新用户,并希望添加一个新列以列出来自数据库的总行数的序列号。
Am new to DynamicReportBuilder
and want to add a new column to list the serial number of the total rows coming from the db.
目前,我已经通过 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());
但问题是,它只显示序列号行中的最后一个计数。这样的事情:
S. No.
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
3
3
3
3
推荐答案
如果你想显示行数您的数据源> jasper报告中的变量值 REPORT_COUNT
,您可以使用 CustomExpression
在报告填写时显示此信息。
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();
}
});
注意:您当前的代码只是循环所有行并更改列的
propertyName
和description
,因此结果为
serialNo.setColumnProperty((count-1)+,String.class.getName(),(count-1)+)
NOTE: Your current code just loops all the rows and changes the
propertyName
anddescription
of the column, hence the result isserialNo.setColumnProperty((count-1)+"",String.class.getName(),(count-1)+"")
这篇关于如何为总条目创建序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!