要求能够给某些指定的报表自定义toolbar。一般而言,可以在URL里使用cv.toolbar=false,但如此一来则所有的toolbar都消失了;同时也可以修改后台system.xml文件添加隐藏元素,但会将牵涉到所有报表。于是就产生了给某些报表自定义toolbar控件,昨天研究出来的方法是,直接重写js即可实现:
优点:
①、根据某些特殊报表的需求,自定义保留或去除toolbar里的某些按钮功能;
②、不会牵涉其它报表
实现方法:
1、打开Report Studio加入HTML控件
2、查看页面原始代码后,复制工具栏的JS代码到HTML
oCV_NS_.rvMainWnd.setToolbar({"namespace":"_NS_","divId":"CVToolbar_NS_","style":"toolbar","S":[...<略>...]}); oCV_NS_.rvMainWnd.init(); oCVSC_NS_.attachObserver(oCV_NS_.rvMainWnd);
3、去除你想要的工具按钮相应的脚本,以及去除主页按钮。
具体实现方法是:在报表中加入html控件,写js代码。如图
删除相关的JS代码,如下
主要是重写了oCV_NS_.rvMainWnd .setToolbar函数,
具体代码如下:
oCV_NS_.rvMainWnd .setToolbar({ "namespace" : "_NS_", "divId" : "CVToolbar_NS_", "style" : "toolbar", "S" : [ { "B" : { "N" : "runIn", "M" : { "id" : "runInoCV_NS_", "Y" : "dropDown", "IS" : [ { "I" : { "N" : "viewInHTML", "A" : "oCV_NS_.getRV().viewReport(\'HTML\');", "E" : "以 HTML 格式查看", "C" : "/p2pd/rv/images/action_view_html.gif" } }, { "I" : { "N" : "viewInPDF", "A" : "oCV_NS_.getRV().viewReport(\'PDF\');", "E" : "以 PDF 格式查看", "C" : "/p2pd/rv/images/action_view_pdf.gif" } }, { "I" : { "N" : "viewInXML", "A" : "oCV_NS_.getRV().viewReport(\'XML\');", "E" : "以 XML 格式查看", "C" : "/p2pd/rv/images/action_view_xml.gif" } }, { "I" : { "N" : "viewInExcel", "E" : "以 Excel 选项查看", "C" : "/p2pd/rv/images/action_view_excel_2000_single_sheet.gif", "M" : { "id" : "viewInExceloCV_NS_", "Y" : "cascaded", "IS" : [ { "I" : { "N" : "viewInspreadsheetML", "A" : "oCV_NS_.getRV().viewReport(\'spreadsheetML\');", "E" : "以 Excel 2007 格式查看", "C" : "/p2pd/rv/images/action_view_excel_2007.gif" } } ] } } } ] } } } ] }); oCV_NS_.rvMainWnd.setBannerToolbar({ "namespace" : "_NS_", "divId" : "CVBanner_NS_", "style" : "banner", "S" : [ { "T" : { "N" : "userName", "E" : "" } }, { "I" : { "N" : "logOnOff", "M" : { "id" : "logOnOffoCV_NS_", "Y" : "dropDown", "H" : "true", "IS" : [] } } }, { "P" : { "Y" : "vertical_line" } }, { "L" : { "N" : "about", "E" : "关于", "A" : "oCV_NS_.getRV().about();" } } ] }); oCV_NS_.rvMainWnd.init(); oCVSC_NS_.attachObserver(oCV_NS_.rvMainWnd);
实现效果如下:
另附cognos8.4的oCV_NS_.rvMainWnd .setToolbar函数的原来全部代码:
oCV_NS_.rvMainWnd .setToolbar({ "namespace" : "_NS_", "divId" : "CVToolbar_NS_", "style" : "toolbar", "S" : [ { "I" : { "N" : "keepThisVersion", "E" : "保留此版本", "C" : "/p2pd/rv/images/action_keep_report.gif", "M" : { "id" : "keepThisVersionoCV_NS_", "Y" : "dropDown", "IS" : [ { "I" : { "N" : "emailReport", "E" : "电子邮件报表", "C" : "/p2pd/rv/images/action_send_report.gif", "A" : "oCV_NS_.getRV().SendReport(false);" } }, { "I" : { "N" : "saveReport", "E" : "保存报表", "C" : "/p2pd/rv/images/action_save_report_output.gif", "A" : "oCV_NS_.getRV().SaveReport(false);" } }, { "I" : { "N" : "saveAsReportView", "E" : "另存为报表视图", "C" : "/p2pd/rv/images/action_save_report_view.gif", "A" : "oCV_NS_.getRV().SaveAsReportView(false);" } } ] } } }, { "P" : { "Y" : "vertical_line" } }, { "P" : { "Y" : "vertical_line" } }, { "B" : { "N" : "runReport", "A" : "oCV_NS_.getRV().RunReport();", "O" : "运行", "C" : "/p2pd/rv/images/action_run.gif" } }, { "P" : { "Y" : "vertical_line" } }, { "B" : { "N" : "drillDown", "A" : "oCV_NS_.getDrillMgr().rvDrillDown();", "O" : "向下追溯", "C" : "/p2pd/rv/images/action_drill_down.gif", "D" : "true" } }, { "B" : { "N" : "drillUp", "A" : "oCV_NS_.getDrillMgr().rvDrillUp();", "O" : "向上追溯", "C" : "/p2pd/rv/images/action_drill_up.gif", "D" : "true" } }, { "B" : { "N" : "goto", "A" : "oCV_NS_.getDrillMgr().launchGoToPage(null, true);", "O" : "转到", "C" : "/p2pd/rv/images/action_go_to.gif", "M" : { "id" : "gotooCV_NS_", "Y" : "dropDown", "A" : "oCV_NS_.getDrillMgr().getDrillThroughParameters();" } } }, { "P" : { "Y" : "vertical_line" } }, { "B" : { "N" : "runIn", "M" : { "id" : "runInoCV_NS_", "Y" : "dropDown", "IS" : [ { "I" : { "N" : "viewInHTML", "A" : "oCV_NS_.getRV().viewReport(\'HTML\');", "E" : "以 HTML 格式查看", "C" : "/p2pd/rv/images/action_view_html.gif" } }, { "I" : { "N" : "viewInPDF", "A" : "oCV_NS_.getRV().viewReport(\'PDF\');", "E" : "以 PDF 格式查看", "C" : "/p2pd/rv/images/action_view_pdf.gif" } }, { "I" : { "N" : "viewInXML", "A" : "oCV_NS_.getRV().viewReport(\'XML\');", "E" : "以 XML 格式查看", "C" : "/p2pd/rv/images/action_view_xml.gif" } }, { "I" : { "N" : "viewInExcel", "E" : "以 Excel 选项查看", "C" : "/p2pd/rv/images/action_view_excel_2000_single_sheet.gif", "M" : { "id" : "viewInExceloCV_NS_", "Y" : "cascaded", "IS" : [ { "I" : { "N" : "viewInCSV", "A" : "oCV_NS_.getRV().viewReport(\'CSV\');", "E" : "以 CSV 格式查看", "C" : "/p2pd/rv/images/action_view_csv.gif" } } ] } } } ] } } }, { "I" : { "N" : "addThisReport", "E" : "添加此报表", "C" : "/p2pd/rv/images/action_add_report.gif", "M" : { "id" : "addThisReportoCV_NS_", "Y" : "dropDown", "IS" : [ { "I" : { "N" : "addToMyFolders", "A" : "oCV_NS_.getRV().launchNewGeneral(\"shortcut\", \"~/folder\");", "E" : "添加至“我的文件夹”", "C" : "/p2pd/rv/images/action_add_Myfolder.gif" } } ] } } }, { "P" : { "Y" : "vertical_line" } }, { "B" : { "N" : "openWith", "M" : { "id" : "openWithoCV_NS_", "Y" : "dropDown", "H" : "true", "IS" : [] } } } ] }); oCV_NS_.rvMainWnd .setBannerToolbar({ "namespace" : "_NS_", "divId" : "CVBanner_NS_", "style" : "banner", "S" : [ { "T" : { "N" : "userName", "E" : "" } }, { "I" : { "N" : "logOnOff", "M" : { "id" : "logOnOffoCV_NS_", "Y" : "dropDown", "H" : "true", "IS" : [] } } }, { "P" : { "Y" : "vertical_line" } }, { "B" : { "N" : "home", "O" : "主页", "C" : "/p2pd/skins/corporate/shared/images/action_home.gif", "A" : "oCV_NS_.getRV().returnHome(\"/p2pd/servlet/dispatch?b_action=xts.run&m=portal/main.xts\");" } }, { "L" : { "N" : "about", "E" : "关于", "A" : "oCV_NS_.getRV().about();" } } ] }); oCV_NS_.rvMainWnd.init(); oCVSC_NS_.attachObserver(oCV_NS_.rvMainWnd);
此函数是cognos8.4版本的,其他版本是否有编号需要去查看,但此文做一个思路仅供参考。