决策报表里使用延时函数实现某些js效果

1. 描述

有的时候有些js代码在cpt里可以运行成功,但是在决策报表里会没有效果,举例:

分页预览改变鼠标悬停所在行背景色代码,在决策报表的报表块使用,预览时没有效果。

2. 思路

这是由于决策报表里没有加载结束后事件,只有初始化后事件,但是我们需要在决策报表加载结束后再执行这段代码,因此我们在代码前面加上setTimeout()延时函数就可以起作用了。

setTimeout(function(){ },1000);

注:setTimeout()延时函数支持移动端。

3. 操作步骤

1)新建决策报表,新建数据集ds1:SELECT * FROM 订单

2)将报表块拖入报表主体,报表块设计如下:

http://help.finereport.com/uploads/201808/20180813154724_6149.png

3)返回表单,选中报表块,添加一个初始化后事件

http://help.finereport.com/uploads/201808/20180813154724_6817.png

编辑该事件添加下面的js代码:

setTimeout(function() {

    var background_color = "rgb(255,0,0)";

    var frozen_back_color = new Array();

    var back_color = new Array();

    var $last_tr;

    var i = 0;

    $(".x-table tr").bind("mouseenter", function() {

        if(typeof($last_tr) != "undefined") {

            if(typeof($(this).attr("id")) != "undefined") {

                if(typeof($("#content-container #frozen-west").attr("id")) != "undefined") {

                    $("#content-container #" + $last_tr.attr("id")).each(function() {

                        $(this).children("td").each(function() {

                            $(this).css("background-color", frozen_back_color[i][$(this).index()]);

                        });

                        i = i + 1;

                    });

                    i = 0;

                } else {

                    $last_tr.children("td").each(function() {

                        $(this).css("background-color", back_color[$(this).index()]);

                    });

                }

                frozen_back_color = [];

                back_color = [];

            }

        }

        if(typeof($(this).attr("id")) != "undefined") {

            if(typeof($("#content-container #frozen-west").attr("id")) != "undefined") {

                $("#content-container #" + $(this).attr("id")).each(function() {

                    frozen_back_color[i] = new Array();

                    $(this).children("td").each(function() {

                        frozen_back_color[i][$(this).index()] = $(this).css("background-color");

                        $(this).css("background-color", background_color);

                    });

                    i = i + 1;

                });

                i = 0;

            } else {

                $(this).children("td").each(function() {

                    back_color[$(this).index()] = $(this).css("background-color");

                    $(this).css("background-color", background_color);

                });

            }

        }

    });

    $(".x-table tr").bind("mouseleave", function() {

        if(typeof($(this).attr("id")) != "undefined") {

            $last_tr = $(this);

        }

    });

}, 1000);

4)保存模板预览。

4. 预览效果

4.1 PC端预览效果

http://help.finereport.com/uploads/201808/20180813154724_3240.gif

4.2 移动端预览效果

注:示例中的js不支持移动端。  

5. 已完成模板

模板效果在线查看请点击:决策报表里使用延时函数实现某些js效果.frm

已完成的模板,可参见:%FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc\JS\表单JS实例\27-决策报表里使用延时函数实现某些js效果.frm

右击存储模板

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值