报表往子报表里传入list

时间:2022-08-07 14:40:14

js

var _parameters = {
    reportFileName: "reports/doctorstation/labBioResult.jasper",
    parameters: {
        'order_Id': $scope.selectedExamLabOrdersVO.orderId,
        'bioList' : bioList,
        'hasAnti' : hasAnti,
        'labAntiList' : labAntiList
    }
};
var printInfoObject = {
    type: "report",
    method: "post",
    appletParameters: {
        is_direct_print: true,
        is_display: false,
        printer_name: null,
        report_url: "api/jasper-prints/doctor-station/lab-bio-results"
    },
    reportParameter: _parameters
};
HrUtils.postMessageToBaseFrame(printInfoObject, "*");

报表服务器的facade里写法

public JasperPrint fillLabBioResultReport(JasperPrintParamsVo jasperPrintParamsVo) {
    LOGGER.debug("填充报表[{}];填充时使用参数:[{}]。", jasperPrintParamsVo.getReportFileName(), jasperPrintParamsVo.getParameters());
    Map reportParam = jasperPrintParamsVo.getParameters();
    List<Map<String, ?>> bioList = (List<Map<String, ?>>) jasperPrintParamsVo.getParameters().get("bioList");
    List<Map<String, ?>> labAntiList = (List<Map<String, ?>>) jasperPrintParamsVo.getParameters().get("labAntiList");
    reportParam.put("bioList", new JRMapCollectionDataSource(bioList));
    reportParam.put("labAntiList", new JRMapCollectionDataSource(labAntiList));
    reportParam.put("SUBREPORT_DIR", "reports/doctorstation/");
    return hrFillReport(obtainJasperReportByFileName(jasperPrintParamsVo.getReportFileName()), reportParam, new JREmptyDataSource());
}

报表写法注意

detail1中循环的是bioList中的数据 detail3中循环的是labAntiList中的数据

报表中传入的bioList和labAntiList的类型要注意(net.sf.jasperreports.engine.data.JRMapCollectionDataSource)

报表往子报表里传入list

连接子报表注意

之前用sql做子报表是下面两个红框有内容(Connection Expression是自动生成的)

现在往子报表中传list是先要把Connection Expression中的值删除然后在紫框中(Data Source Expression)填入($P{bioList}.cloneDataSource())

  $P{bioList}是要往子报表中传的list也是主报表中的parameter的值

报表往子报表里传入list