[{"id":"bcb0874d-299b-448e-9552-9e9b25ef80dd","tags":[{"product":null,"links":null,"id":"ba7e818e-4f6b-4211-b1ac-58e3bafcf439","name":"\u66F4\u65B0","color":"orange","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"8ce3627e-9e58-471b-9133-4f135d191e7b","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"ae60ae59-34f5-4f32-a8eb-243ed1457543","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"3d4848c3-910f-4ffa-9153-60bb507334a9","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"133f4ca6-d951-4d65-a618-3dc6301266f7","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"de62ec1c-813e-40b1-8160-a4cd109afe64","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"2426c71d-8332-4cbd-a436-1ec4f8666464","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"2ce7b6b0-78aa-4e4b-bf8a-e4ba2f988298","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"4706db46-0811-4652-8f59-1e0a1da84758","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"8f1271bb-2cd9-4f39-9897-c15b239ee7ab","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"677e13a7-6f3e-449f-986c-2c3a26f8d54f","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"5e40f6dc-caec-49d7-a1d0-be65f06815ba","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"2457f0e0-9e71-4860-a87d-065e0fb84f84","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"d5c67fd0-1145-482c-9113-97b492c44c18","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"a609a8fa-ab91-4c1d-a1c3-d209d0463303","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"b4a9eb15-94e5-48df-b218-a24138f0cf9c","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]}]
一般情况下,报表的组件是固定的,但也有一些情况需要动态的显示组件。比如以下两种场景:
允许用户自定义显示组件,以提高阅读效率。如图所示。
根据登录用户的权限自动控制显示组件。比如当 Administrator 角色登录时可以看到报表中的所有内容,而当普通角色登录查看此报表时则仅能看到图表内容,不能看到表格内容。如图所示
下面为您分别介绍这两种动态显示组件效果在报表中的实现方法。
1. 新建报表,添加基于 WynDemoData 的数据集,并创建如下图表和表格。
2. 添加一个报表参数,并按下图所示编辑参数设置项。
3. 选中图表组件,在属性设置面板中找到显示选项的隐藏设置项,单击右侧的小方块,然后选择表达式。
4. 在表达式编辑器中输入表达式: {IIF(Join(@P1, ",").IndexOf("图表") >= 0, false, true)} 。
表达式含义:先将参数P1转换成字符串,然后检测是否包含“ 图表 ”,如果包含则返回“ False ”,如果不包含则返回“ True ”。
由于表达式是添加在了隐藏设置项中,因此如果返回“ False ”也即不隐藏,返回“ True ”则隐藏。
5. 同理,在表格的属性设置中找到隐藏设置项,然后为其添加表达式: {IIF(Join(@P1, ",").IndexOf("表格") >= 0, false, true)}。
6. 预览报表,可见已经实现组件的动态控制效果。
根据用户权限控制组件显示情况的做法与以上通过参数面板进行控制的原理相同,都是在组件的隐藏设置项中添加表达式,然后通过表达式来实现动态控制。
具体做法如下:
选中表格组件,在属性设置面板中找到显示选项下的隐藏设置项,单击右侧的小方块,然后选择表达式。
在表达式编辑器中输入表达式: {IIF(Join(UserContext.GetValues("role"), ",").IndexOf("administrator") >= 0, false, true)} 。
表达式含义:先获取到当前登录用户的角色值并将其转换成字符串,然后检测是否为“ administrator ”,如果是则返回“ False ”,如果不是则返回“ True ”。
由于表达式是添加在了隐藏设置项中,因此如果返回“ False ”也即不隐藏,返回“ True ”则隐藏。
预览报表。当前登录用户为administrator,因此可以看到表格组件;如将文档分享给其他角色,并切换至其他角色的用户登录,则只能看到图表组件。