How to run a vertical report (column as value) using DynamicJasper?

485 Views Asked by At

I have a requirement for running a vertical report, where columns name will be displayed in a row with adjacent value like key value pair.

I'm trying to use the property, printOrder but not sure where i can implement the same.

I have tried the same using CROSS Apply SQL Query to get the column name and value as a key value pair, but it's difficult to distinguish between 2 different records in the report.

The following is the code i'm running:

drb = new DynamicReportBuilder();
drb.setMargins(10, 10, 10, 10)
    .setTitleHeight(50)
    .setDetailHeight(12)
    .setHeaderHeight(22)
    .setGrandTotalLegend("Total Count : ")
    .setGrandTotalLegendStyle(headerVariables)
    .setPrintBackgroundOnOddRows(true)
    .setDefaultStyles(titleStyle, null, headerStyle, detailStyle)
    .setPageSizeAndOrientation(Page.Page_A4_Landscape());

AbstractColumn callID = ColumnBuilder.getNew()
    .setColumnProperty("Cname", String.class.getName())
    .setTitle("COLUMN NAME").setWidth(80).build();

AbstractColumn   callbeginTime = ColumnBuilder.getNew()
    .setColumnProperty("data", String.class.getName())
    .setTitle("CALL DATA").setWidth(80).build();
drb.addColumn(callID);
drb.addColumn(callbeginTime);
drb.setTitle("New report");

drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_SLASH_Y, AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_RIGHT);

drb.setAllowDetailSplit(false);
drb.setUseFullPageWidth(true); 
drb.setPrintColumnNames(true);

Map<String, Object> params = new HashMap<String, Object> ();

params.put("reportTitle", "New report");
params.put("date", dtLong.format(new Date()));
params.put("reportFormat", "pdf");

DynamicReport dr = drb.build(); //create dynamic report object
//using dynamic report
JasperReport jr = DynamicJasperHelper.generateJasperReport(dr, getLayoutManager(),params);

DynamicJasperDesign dynamicJasperDesign = DynamicJasperHelper.generateJasperDesign(dr);

JRSwapFile swapFile = new JRSwapFile("E:\\report files\\", 1024, 100);
JRSwapFileVirtualizer swapVirtualizer = new JRSwapFileVirtualizer(50, swapFile, true);
System.out.println("dddd2");
params.put(StandardListComponent.PROPERTY_PRINT_ORDER,PrintOrderEnum.VERTICAL); 
params.put(JRParameter.REPORT_VIRTUALIZER, swapVirtualizer);

JasperPrint jp = JasperFillManager.fillReport(jr, params, new 

JRResultSetDataSource(ResultSet));
jp.setProperty(StandardListComponent.PROPERTY_PRINT_ORDER,"VERTICAL");

JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);

exporter.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, "e:\\report files\\final"+Math.random()+".pdf");
exporter.exportReport();

With dynamic reports i'm getting values as below:

COL1    | COL2   | COL3 
ROW1C1  | ROW1C2 | ROW1C3
ROW2C1  | ROW2C2 | ROW2C3

Expected Result:

COLUMN NAME | COLUMN VALUE
COL1        | ROW1C1
COL2        | ROW1C2 
COL3        | ROW1C3 
COL1        | ROW2C1
COL2        | ROW2C2 
COL3        | ROW2C3 
1

There are 1 best solutions below

1
Dj Mamana On

Always think of DynamicJasper as a convenient tool/wrapper of JasperReports. If JasperReport by itself cannot do what you need, neither DJ will.

My advice is to first try to get a simple version (non dynamic) of your report using bare JasperReport (by using iReport/JasperStudio) if you manage to get your report, then we can think of a way to figure out how to achieve this using DJ.

Most of the time, if its doable, you'll easily get what properties/configurations were needed and you'll know how to build your report using DJ.