提示:本文档的示例代码仅适用于本文档中的示例报表/场景。若实际报表/场景与示例代码无法完全适配(如使用功能不一致,或多个宏代码冲突等),需根据实际需求开发代码。
示例说明
在灵活分析中切换一个参数,不同的参数值打开不同的报表。如下图:
切换【报表】参数,值为1的时候显示报表1:
切换【报表】参数,值为2的时候显示报表2:
切换【报表】参数,值为3的时候显示报表3:
设置方法
- 在公共设置中,创建【报表】参数。
- 在资源定制中,创建报表1、报表2、报表3对应的查询,要求所有查询都需要在where条件中添加"报表参数"="报表参数",如下图:
- 在资源定制中使用上面查询分别创建灵活分析对于的报表1、报表2、报表3。
- 到 公共设置—宏资源包 节点,右键选择新建一个资源包,类型选择灵活分析,适用范围选择报表1、报表2和报表3。
- 双击此资源包进入报表宏界面。
- 在报表宏界面新建客户端模块,在弹出的新建模块对话框中选择对象为simpleReport;事件为onParamValueChanged;并把下面宏代码复制到代码区域。
宏类型
类型 | 对象 | 事件 |
ClientSide | simpleReport | onParamValueChanged |
宏代码
function main(simpleReport, simpleReportContext, param) { var destQuery = null; if (param.name == "报表") { if (param.value == 1) destQuery = simpleReportContext.openReport('I4028818a2578cab101522681313b0183'); //报表1的ID else if (param.value == 2) destQuery = simpleReportContext.openReport('I4028818a2578cab10152268375b10228'); //报表2 的ID else destQuery = simpleReportContext.openReport('I4028818a2578cab1015226845cfd0273'); //报表3的ID realValue = param.value dispValue = param.displayValue; if (realValue && dispValue) destQuery.fillParamValue('报表', realValue, dispValue); destQuery.refreshData(); } }
关键对象总结
- 目标报表填充参数对象:destQuery.fillParamValue('报表', realValue, dispValue);
- 打开灵活分析:simpleReportContext.openReport("I2c949eaf1a942102011a9561f7e7015d");
资源下载:migrate根据参数值不同显示不同的报表.xml