0

I am using JRBeanCollectionDataSource as datasource for a subreport. Each record in the list contains elements with either null or non-null value . This is my POJO:

public class PayslipDtl {

        private String earningSalaryHeadName;
        private double earningSalaryHeadAmount;

        private String deductionSalaryHeadName;
        private double deductionSalaryHeadAmount;

        String type;

public PayslipDtl(String salaryHeadName,
            double salaryHeadAmount, String type) {
        if(type.equalsIgnoreCase("Earning")) {
            earningSalaryHeadName = salaryHeadName;
            earningSalaryHeadAmount = salaryHeadAmount;
         } else { 
            deductionSalaryHeadName = salaryHeadAmount;
            deductionSalaryHeadAmount = salaryHeadAmount;
        }
    }

        //getters and setters
        }

Based on the "type", the list is populated as such: {"Basic", 4755, null, 0.0}, {"HRA", 300, null, 0.0}, {null, 0.0, "Employee PF", 925}, {"Medical Allowance", 900, null, 0.0} and so on...

After setting isBlankWhenNull to true and using "Print when" expression, the record is displayed as such:

|Earning            |Amount|Deduction            |Amount|
--------------------|------|---------------------|------|
| Basic             | 4755 |                     |      |
| HRA               | 300  |                     |      |
|                   |      | Employee PF         |  925 |
| Medical Allowance | 900  |                     |      |
| Fuel Reimbursement| 350  |                     |      |
|                   |      | Loan                | 1000 |
---------------------------------------------------------

I want it to be displayed as such:

|Earning            |Amount|Deduction            |Amount|
--------------------|------|---------------------|------|
| Basic             | 4755 |  Employee PF        |  925 |
| HRA               | 300  |  Loan               | 1000 |
| Medical Allowance | 900  |                     |      |
| Fuel Reimbursement| 350  |                     |      |
---------------------------------------------------------

Setting isRemoveLineWhenBlank to true doesn't work since it is not the entire row which is blank but only a subset of elements of a row that is null.

Is it possible in Jasper?

I am using iReport Designer 5.0.1 with compatibility set to JasperReports3.5.1.

4

2 回答 2

0

Use a List component for the deduction/amount, here you have a video tutorial on how to do this.

Then deduction and amount fields on the list component need the following options Blank when null and Remove line when blank.

If this still gives you blank lines, try putting both fields on a frame inside the list and mark those options for the frame too.

于 2013-04-19T11:40:01.473 回答
0

只有一个好的解决方案是,您必须创建单独的表:

table employeeED:
srno int,
Earning varchar(50),
EarnAmount Double,
Deduction varchar(50)
DedAmount Double

然后你必须在收入方面插入所有收入并在扣除方面更新所有扣除。

    int i=1;
    rs.first();
    while(rs.next())
    {
         if(rs.getString("type").equals("Earning"))
            Insert into employeeEd (srno, Earning,EarnAmount) values     (i, rs('earning'), rs('eamt'))
    }

    int j=1;
    rs.first();
    while(rs.next())
    {
        if(rs.getString("type").equals("deduction"))
           update employeeEd set Deductions='"+rs('earning')+"',  DedAmount=" + rs('eamt') + " where srno="+j)
        j++;
    }

然后使用employeeED 表作为数据源。100% 工作。

于 2017-02-12T14:25:01.647 回答