找回密码
 立即注册

QQ登录

只需一步,快速开始

Lenka.Guo 讲师达人认证 悬赏达人认证
超级版主   /  发表于:2021-5-31 10:42  /   查看:2323  /  回复:0
有一些特定情况下,如离线环境,数据由用户本地输入后重组数据在本地形成新的可用数据在展示报表中,这些特殊情况下导致了,我们需要在运行时修改报表数据源。
ActiveReportsJS 报表本身为JSON 结构,因此可以通过读取报表的JSON 结构后,再修改数据源是一个非常好的方法,ActiveReportsJS 提供了运行时修改数据源的实例:https://demo.grapecity.com.cn/ac ... data-binding/purejs

但在这种情况下,我们又存在一个问题,当报表发生钻取到子报表操作时,子报表也需要运行时修改数据源,我们便无法通过读取JSON 字串,再去修改子报表的数据源。

此种情况下,可结合 ActiveReportsJS 提供的 resource locator 和内嵌数据集来解决这个需求。
ResourceLocator接口:可实现资源重定向功能,如子报表路径,图片子源,数据源资源,钻取子报表等资源。


具体实例代码参考


1. 创建主子报表,并设置内嵌数据源和数据集,完成报表设计




2. 定义函数,读取主子报表JSON 字串,并修改数据源
  1.   const mainReport = await fetch(
  2.         '/assets/drill-mainreport.rdlx-json'
  3.       ).then((resJson) => resJson.json());
  4.       const mainData = await fetch(
  5.         'https://demodata.grapecity.com/northwind/api/v1/Categories'
  6.       ).then((resJson) => resJson.json());
  7.       mainReport.DataSources[0].ConnectionProperties.ConnectString =
  8.         'jsondata=' + JSON.stringify(mainData);

  9.       const subReport = await fetch(
  10.         '/assets/drill-subreport.rdlx-json'
  11.       ).then((resJson) => resJson.json());
  12.       const subData = await fetch(
  13.         'https://demodata.grapecity.com/northwind/api/v1/Products'
  14.       ).then((resJson) => resJson.json());
  15.       subReport.DataSources[0].ConnectionProperties.ConnectString =
  16.         'jsondata=' + JSON.stringify(subData);
复制代码


3. 定义resourceLocator, 该接口包含两个方法 getResource, getResourceId
再 getResource 中指定reportViewer.open 方法
const resourceLocator = {
        getResource: function (name) {
          if (name === 'productList.rdlx-json') return subReport;
        },
      };

    };



4. 指定打开主报表,并调用 ResourceeLocator API。
this.reportViewer.open(mainReport, { ResourceLocator: resourceLocator });


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部