报表超链接跳转、表头字段排序

栏目:云星瀚知识作者:金蝶来源:金蝶云社区发布:2024-09-22浏览:1

报表超链接跳转、表头字段排序

1.    报表超链接跳转开发指引

以物料收发汇总表跳转物料收发明细表为例

1.1点击物料编码超链接,跳转物料收发明细表,效果如下:


1.2 代码实现步骤如下:

报表插件大致分为表单类插件查询插件,查询插件可处理报表查询时的取数等逻辑,表单插件可处理过滤面板的控制逻辑。

1.2.1 查询时需要的字段设置为超链接显示(本例中即为物料编码字段)

报表数据源配置的扩展插件中留有扩展点,buildShowColumn方法中可设置查询后字段显示为超链接:


代码示例(可参考汇总表扩展插件

1. public final class SumRptHandle implements IReportDataHandle {  

2.     @Override  

3.     public List<AbstractReportColumn> buildShowColumn(List<AbstractReportColumn> columns, ReportDataCtx ctx) {  

4.         Set<String> showQtyCols = ctx.getShowQtyCols();  

5.         List<AbstractReportColumn> showCols = new ArrayList<>(16);  

6.         ReportColumn reportCol = null;  

7.         String field = null;  

8.         for (AbstractReportColumn col : columns) {  

9.             // 物料设置为超链接  

10.             if ("material".equals(field)) {  

11.                 reportCol.setHyperlink(true);  

12.             }  

13.         }  

14.         return showCols;  

15.     }  

16.


1.2.2 点击超链接跳转页面:

跳转逻辑需要在汇总表(新)表单插件中处理,代码示例

1. public final class SumRptForm extends AbstractReportFormPlugin implements HyperLinkClickListener{  

2.             @override  

3.             public void hyperLinkClick(HyperLinkClickEvent e) {  

4.                 String key = e.getFieldName();  

5.                 if ("material".equals(key)) {  

6.                     // 点击超链接,打开对应表单  

7.                     this.showDetailRpt(e);  

8.                 }  

9.             }  

10.               

11.             /* 

12.             * 设置跳转参数 

13.             */  

14.             private void showDetailRpt(HyperLinkClickEvent e) {  

15.                 ReportShowParameter rsp = new ReportShowParameter();  

16.                 // 设置需要打开的页面标识  

17.                 rsp.setFormId("im_detail_rpt");  

18.                 // 显示模式  

19.                 rsp.getOpenStyle().setShowType(ShowType.MainNewTabPage);  

20.                 // 设置跳转到明细表时需要设置的过滤条件,用于打开明细表时获取该参数后处理过滤  

21.                 OpenDetailParam param = this.buildOpenDetailParam(e);  

22.                 rsp.setCustomParam(OpenDetailParam.class.getName(), SerializationUtils.toJsonString(param));  

23.                 this.getView().showForm(rsp);  

24.             }  

25.             /* 

26.             * 设置跳转到明细表时需要设置的过滤条件,用于过滤明细表 

27.             */  

28.             private OpenDetailParam buildOpenDetailParam(HyperLinkClickEvent e) {  

29.                 OpenDetailParam param = new OpenDetailParam();  

30.                 RptForm RptForm = this.getRptForm();  

31.                 param.setOrgId(RptForm.getOrgIds());  

32.                 DynamicObject data = this.getModel().getDataEntity();  

33.                 param.setDateFrom(data.getDate("startdate"));  

34.                 param.setDateTo(data.getDate("enddate"));  

35.                 param.setGroupStandard(data.getDynamicObject("groupstandard").getLong("id"));  

36.                 param.setGroupFrom(RptUtil.getBaseDataObjIds(this.getView(), "groupfrom"));  

37.                 DynamicObject baseData = data.getDynamicObject("groupto");  

38.                 if (baseData != null) {  

39.                     param.setGroupTo(baseData.getPkValue());  

40.                 }  

41.   

42.                 param.setMaterialFrom(RptUtil.getBaseDataObjIds(this.getView(), "materialfrom"));  

43.                 baseData = data.getDynamicObject("materialto");  

44.                 if (baseData != null) {  

45.                     param.setMaterialTo(baseData.getPkValue());  

46.                 }  

47.   

48.                 param.setMaterialType(data.getString("materialtype"));  

49.                 param.setShowQtys(data.getString("showqtycols"));  

50.                 param.setIncludeSubmit(data.getBoolean("include_submit"));  

51.                 param.setIncludeUnupdate(data.getBoolean("include_unupdate"));  

52.                 param.setIncludeInQty(data.getBoolean("display_in"));  

53.                 param.setIncludeOutQty(data.getBoolean("display_out"));  

54.                 param.setIncludeInitBalQty(data.getBoolean("display_init_bal"));  

55.                 FilterGrid grid = (FilterGrid)this.getControl("commonfs");  

56.                 FilterCondition condition = grid.getFilterGridState().getFilterCondition();  

57.                 param.setCondition(condition);  

58.                 this.reBuildReportParms(param, e);  

59.                 return param;  

60.             }  

61.     }  

62. }

跳转到明细表后,明细表的处理逻辑分为两步:

1)需要获取到汇总表跳转时设置的过滤条件,设置到明细表过滤条件中;

2)调用明细表查询逻辑;

这部分逻辑需要在明细表(新)表单插件处理,代码示例

1. public final class DetailRptForm extends AbstractReportFormPlugin{  

2.     @override  

3.     public void afterCreateNewData(EventObject e) {  

4.         // 获取参数,根据param判断是否为汇总表超链接打开  

5.         OpenDetailParam param = this.getOpenDetailParam();  

6.         if (param == null) {  

7.             this.init4DirectOpen();  

8.         } else {  

9.             // 打开明细表方式为汇总表超链接打开  

10.             this.init4LinkOpen(param);  

11.             // 清空传过来的条件,避免重置时再次走到该逻辑  

12.             this.getPageCache().put("linkOpened""true");  

13.         }  

14.   

15.     }  

16.       

17.       

18.     private static final String LINK_OPENED = "linkOpened";  

19.       

20.     private boolean isLoadOpenDetailParam;  

21.     private OpenDetailParam openParam;  

22.       

23.     /* 

24.     * 获取汇总表传递的过滤参数 

25.     */  

26.     private OpenDetailParam getOpenDetailParam(){  

27.         if(!isLoadOpenDetailParam){  

28.             if(this.getPageCache().get(LINK_OPENED)==null){  

29.                 FormShowParameter fsp = this.getView().getFormShowParameter();  

30.                 String openParamStr = fsp.getCustomParam(OpenDetailParam.class.getName());  

31.                 if(StringUtils.isNotBlank(openParamStr)){  

32.                     openParam = SerializationUtils.fromJsonString(openParamStr, OpenDetailParam.class);  

33.                 }  

34.             }  

35.             isLoadOpenDetailParam = true;  

36.         }  

37.         return openParam;  

38.     }  

39.       

40.     /* 

41.     * 根据汇总表传递的参数设置明细表的过滤条件 

42.     */  

43.     private void init4LinkOpen(OpenDetailParam param) {  

44.         RptForm RptForm = this.getRptForm();  

45.         Set<String> needCols = new HashSet(1);  

46.         needCols.add("auxpty");  

47.         RptForm.removeFilterGridCols(this.getRemoveFilterGridCols(), needCols);  

48.         this.handleAuxptyFs();  

49.         RptForm.initOrg(param.getOrgId());  

50.         IDataModel model = this.getModel();  

51.         // 设置日期条件  

52.         model.setValue("startdate"param.getDateFrom());  

53.         model.setValue("enddate"param.getDateTo());  

54.         model.setValue("materialtype", param.getMaterialType());  

55.         model.setValue("groupstandard", param.getGroupStandard());  

56.         List<Object> tempIds = param.getGroupFrom();  

57.         model.setValue("groupfrom", tempIds == null ? new Object[0] : tempIds.toArray());  

58.         model.setValue("groupto"param.getGroupTo());  

59.         tempIds = param.getMaterialFrom();  

60.         // 设置物料条件  

61.         model.setValue("materialfrom", tempIds == null ? new Object[0] : tempIds.toArray());  

62.         model.setValue("materialto"param.getMaterialTo());  

63.         model.setValue("include_submit", param.isIncludeSubmit());  

64.         model.setValue("include_unupdate", param.isIncludeUnupdate());  

65.         model.setValue("showqtycols", String.join(",", param.getShowQtys()));  

66.         this.buildAuxptyEntry(param);  

67.         FilterGrid filterGrid = (FilterGrid)this.getView().getControl("commonfs");  

68.         filterGrid.SetValue(param.getCondition());  

69.         model.setValue("display_init_bal", param.isIncludeInitBalQty());  

70.         model.setValue("display_in"param.isIncludeInQty());  

71.         model.setValue("display_out", param.isIncludeOutQty());  

72.     }  

73.       

74.     @override  

75.     public void afterBindData(EventObject e) {  

76.         super.afterBindData(e);  

77.         if (this.getOpenDetailParam() != null) {  

78.             ReportFilter filter = (ReportFilter)this.getControl("reportfilterap");  

79.             // 手动调用明细表查询  

80.             filter.search();  

确认删除?