1. 概述
1.1 問題描述
在我們使用填報表時,有時只需要提交按鈕将數據入庫,不希望使用 FR 内置的工具欄的按鈕,希望能夠自定義提交按鈕。
自定義按鈕既可以是 FineReport 模板中添加的按鈕控件,也可以是 Web 集成頁面中,HTML 的按鈕标簽。
(1)FineReport 模板中的按鈕控件實現自定義提交操作詳細請參照 自定義按鈕中實現提交操作;
(2)而在 Web 頁面中,點擊 HTML 中的按鈕提交 iframe 中的 FineReport 報表就在下面詳述。
效果如下圖:
1.2 實現思路
FR 中内置的報表提交 JS 代碼是contentPane.writeReport(),如果是調用嵌入的報表提交功能的話,使用document.getElementById('報表所在iframe的id').contentWindow.contentPane.writeReport();
2. 操作步驟
2.1 編輯模板
使用模板%FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc\Form\FreeFrom\FreeForm.cpt
2.2 編輯 HTML 代碼
在網頁中添加按鈕代碼如下:
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.writeReport()">提交</button>
完整代碼:
<html>
<head>
<title>自定義提交按鈕</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="toolbar">
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.writeReport()">提交</button>
</div>
<iframe id="reportFrame" onload="afterload()" src="/webroot/decision/view/report?viewlet=doc/Form/FreeFrom/FreeForm.cpt&op=write&__showtoolbar__=false" width = 100% height = 80%></iframe>
</body>
</html>
已完成示例請參照%FR_HOME%\webapps\webroot\help\page_demo\write.html
2.3 效果預覽
啓動設計器,在浏覽器輸入:http://localhost:8075/webroot/help/page_demo/write.html,效果如下圖: