How to create a Serial Number for total entries?

╄→гoц情女王★ 提交于 2019-12-11 06:04:48

问题


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 propertyName and description of the column, hence the result is serialNo.setColumnProperty((count-1)+"",String.class.getName(),(count-1)+"")



来源:https://stackoverflow.com/questions/38871660/how-to-create-a-serial-number-for-total-entries

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