Search code examples
sqljasper-reports

How to split information on different tables within one report?


I need to display the information of the Main Report in two tables, each of them containing data filtered based on a condition X (1- Bigger than X, 2 - Smaller than X). I tried to create separate data-sets for each table but it leads to an increase on time load. How can I fill different tables within the report, with different filtered information based on main report?


Solution

  • If you have a field listRecords of type collection with all your records, you can define the table datasource as :

    new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(
        Collections2.filter($F{listRecords}, new Predicate<Integer>() {
            @Override
            public boolean apply(final Integer input) {
                return input > 2;
            }
        })
    )
    

    Using the guava library to filter the collection.