页面树结构
转至元数据结尾
转至元数据起始

提示:本文档的示例代码仅适用于本文档中的示例报表/场景。若实际报表/场景与示例代码无法完全适配(如使用功能不一致,或多个宏代码冲突等),需根据实际需求开发代码。

示例说明

        在灵活分析报表中,显示快捷工具栏,并在其上添加一个新的按钮。该按钮用来控制是否显示参数面版,对于该需求,可以通过客户端宏代码实现。

        显示参数面版,效果图如下:

        

        隐藏参数面版,效果图如下:

        

设置方法

  1. 在资源定制界面,创建灵活分析报表。
  2. 选中灵活分析,右键选择 编辑宏 进入报表宏界面。
  3. 在报表宏界面新建客户端模块。在弹出的新建模块对话框中选择对象为 simpleReport;事件为 onRender;并把下面宏代码复制到代码区域。



宏类型

类型

对象

事件

ClientSide

simpleReport

onRender

宏代码

function main(simpleReport, simpleReportContext) {
    var tr = document.createElement("tr"); //创建行
    var td = document.createElement("td"); //创建列
    tr.appendChild(td); //在行中添加列
    simpleReport.hiddenParamButton = document.createElement("input");
    simpleReport.hiddenParamButton.setAttribute("type", "button");
    simpleReport.hiddenParamButton.setAttribute("value", "隐藏条件");
    simpleReport.hiddenParamButton.setAttribute("class", "button-buttonbar-noimage");
    td.appendChild(simpleReport.hiddenParamButton); //在列中添加按钮
    simpleReport.shortcut.parentNode.appendChild(tr); //在参数面版本中添加行
    simpleReport.shortcut.parentNode.insertBefore(tr, simpleReport.shortcut); //在参数行后面添加创建的行
    /*按钮事件方式*/
    var doHiddenParamClick = function() {
        if (this.hiddenParamButton.value == "隐藏条件") {
            this.paramLay.style.display = "none";
            this.hiddenParamButton.value = "显示条件";
        } else {
            this.paramLay.style.display = "";
            this.hiddenParamButton.value = "隐藏条件";
        }
    }
    simpleReport.addListener(simpleReport.hiddenParamButton, "click", doHiddenParamClick, simpleReport); //在按钮上添加事件
}


关键对象总结

  • 参数面版本是否显示:this.paramLay.style.display ;
  • 为新添加按钮绑定事件处理函数:simpleReport.addListener(simpleReport.hiddenParamButton, "click", doHiddenParamClick, simpleReport);


  • 无标签