历史版本2 :自定义参数界面和工具栏 返回文档
编辑时间: 内容长度:图片数:目录数: 修改原因:

1. 问题描述编辑

FineReport本身自带多种可编辑控件,可以实现复杂参数界面的制作。但是有时为了实现与系统界面中控件的一致性,希望不使用FR内置的参数界面和内置工具栏,而是自己定义参数界面以及工具栏,此时要如何设置呢?

2. 解决思路编辑

自定义参数界面中介绍了自定义按钮的实现方式,在自定义工具栏章节中介绍了各种按钮的实现方式,那么只需要将这两个实现过程结合起来即可。

3. 示例编辑

以自定义参数界面中的最终模板/demo/parameter/number1.cpt模板为例,将其嵌入到页面中去,并且不显示模板参数界面和内置工具栏。
3.1 效果
效果如下图所示
输入最小库存量,点击查询,就会提交参数值给number1.cpt模板,并且在该页面显示过滤结果。
3.2 网页设计
网页设计参见自定义参数界面并传参,只需要再添加一个工具栏即可,工具栏添加的详细介绍请查看自定义工具栏按钮
在网页中添加如下代码:
  1. <body>  
  2.  <!-- 自定义工具栏-->    
  3.     <div id="toolbar">         
  4.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoFirstPage()">首页</button>    
  5.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoPreviousPage()">上一页</button>         
  6.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoNextPage()">下一页</button>         
  7.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoLastPage()">末页</button>                
  8.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.flashPrint()">客户端FLASH打印</button>            
  9.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('page')">导出[Excel](分页)</button>    
  10.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToWord()">导出[Word]</button>                
  11.     </div>    
完整代码如下
  1. <html>  
  2.   <head>    
  3.   <title>FineReport Demo</title>    
  4.   <meta http-equiv="Content-Type" content="text/html; charset=GBK" />    
  5.   <script type="text/javascript">  
  6.     //cjkEncode方法的实现代码,放在网页head中或者用户自己的js文件中  
  7.     function cjkEncode(text) {                                                                            
  8.       if (text == null) {         
  9.         return "";         
  10.       }         
  11.       var newText = "";         
  12.       for (var i = 0; i < text.length; i++) {         
  13.         var code = text.charCodeAt (i);          
  14.         if (code >= 128 || code == 91 || code == 93) {  //91 is "[", 93 is "]".         
  15.           newText += "[" + code.toString(16) + "]";         
  16.         } else {         
  17.           newText += text.charAt(i);         
  18.         }         
  19.       }         
  20.       return newText;         
  21.     }     
  22.   
  23.     function autoSubmit() {  
  24.       var num = document.getElementById('num').value; //获取文本控件的值  
  25.       var row = document.getElementById('row').value; //获取下拉框控件的值  
  26.       //拼接出最终报表访问路径,并对完整的路径进行编码转换,防止乱码问题  
  27.       var reportURL = cjkEncode("/WebReport/ReportServer?reportlet=/demo/parameter/number1.cpt¶=" + num + "&row=" + row);  
  28.       document.paraForm.action = reportURL; //通过form的name获取表单,并将报表访问路径赋给表单的action  
  29.       document.paraForm.submit(); //触发表单提交事件  
  30.     }  
  31.   </script>  
  32.   </head>    
  33.   <body>  
  34.    
  35.     <fieldset>  
  36.     <legend>查询表单:</legend>  
  37.     <form name="paraForm" method="post" target="reportFrame">  
  38.         最小库存量:<input type="text" name="num" id="num" value="1"/>  
  39.         每页显示行数:<select name="row" id="row">    
  40.         <option value="10" select>10    
  41.         <option value="20">20  
  42.         <option value="30">30  
  43.         <input type="button" name="show" value="查询" onclick="autoSubmit()"/>  
  44.     </form> <!-- 自定义工具栏-->    
  45.     <div id="toolbar">         
  46.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoFirstPage()">首页</button>    
  47.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoPreviousPage()">上一页</button>         
  48.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoNextPage()">下一页</button>         
  49.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.gotoLastPage()">末页</button>                
  50.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.flashPrint()">客户端FLASH打印</button>            
  51.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('page')">导出[Excel](分页)</button>    
  52.     <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToWord()">导出[Word]</button>                
  53.     </div>    
  54.     </fieldset>  
  55.     <iframe id="reportFrame" name="reportFrame" width="100%" height="100%" ></iframe>    
  56.   </body>    
  57. </html>  
已完成页面请参照%FR_HOME%\WebReport\page_demo\parameter_toolbar.html.
在浏览器中输入http://localhost:8075/WebReport/page_demo/parameter_toolbar.html即可查看效果。

在线查看示例效果请点击parameter_toolbar.html