I am using Jasper Reports and I am wondering how you can create a data-table-like element in your reports. What I want to do basically is create a report which display records in a data table. The records may vary in size (i.e. the number of rows may differ), so hardcoding the records into static XML elements is not an option. The data of the records by the way is coming from a Java Bean datasource, and not from a database query. I know Jasper Reports has no built-in element to handle data-table-like displays, which is quite frustrating and surprising since most reports require some tabular data for display. Can somebody please help, it will be greatly appreciated. Thanks in advance.
There's so much to learn in this industry, and not everybody has the necessary interest.
JasperReports handles this quite well, actually. This is fairly easy is the number of rows is all that is changing. (If the columns change as well, you can fake it with a cross-tabulation report, but that is frustrating to work with in any reporting system).
Usually, I create a List of records in a subclass of the JRDataSource class and pass that datasource to the report. The Details section of the report is then repeated once for each record returned by the call to .next() in the datasource. Yyou have to implement the stepping-though-the-list code and the get-value-for-the-field code youself; I usually do something like:
Then, I implement the getFieldValue as basically a big switch method -- if the field name is "FOO" I return the value data.getFoo(). (Or, most of the time I just create lists of Maps and simply return data.get(fieldName));
There you go -- instant data table.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joined: May 18, 2006
Wow! Thanks Joel this worked great for me. Cheers man!