• 与CDF中的TableComponent组件交互 转自Pedro Alves on Business Intelligence


    原文在blogspot上,blogspot已经被墙了。可惜,可惜。

    Interacting with the TableComponent

    It's been usual to see someone asking for interaction with the TableComponent in CDF. While it's true that we don't support that out of the box, it's incredibly easy to add it. Well, maybe not incredibly easy to everyone, but that's what blogs are for :)


    To achieve that we'll use the amazingly useful postExecution function. It allows us to execute whatever we want after the component is rendered. Since CDF internally uses JQuery we have almost no restrictions to what we can do.


    We'll use the bind and live functions of jquery. Let's define our click function:


    var clickFunction = function(){
    alert("You clicked on: " + $(this).text())
    }




    And in our postExecution we'll add a call for it. I'll use the sample in the documentation


    var topTenCustomers =
    {
    name: "topTenCustomers",
    type: "tableComponent",
    chartDefinition: MetaLayerHome2.topTenCustomerDefinition,
    htmlObject: "sampleObject",
    executeAtStart: true,
    postExecution: function(){
    var cols = $("#sampleObject td:nth-child(1)");
    cols.die("click");
    cols.live("click",clickFunction);
    }
    };



    Some explanations. With the help of selectors we selected every first row (index on nth-child starts at 1). We can select whatever column(s) we want. Then I attached the clickFunction to the click event on those cells.

    The reason I used live instead of bind is subtle - this way, when we change pages or filter within our component it will still work.

    And that's it. In a real-world scenario we'd probably replace the alert() with something like the Dashboards.fireChange function like we do in charts, but you get the idea.

    Of course we can play a bit around this idea. Here's my final alternative to the tablecomponent component reference example:





    var MetaLayerHome2 = {
    topTenCustomerDefinition: {
    colHeaders: ["Customers","Sales"],
    colTypes: ['string','numeric'],
    colFormats: [null,'%.0f'],
    queryType: 'mdx',
    displayLength: 5,

    catalog: 'solution:steel-wheels/analysis/steelwheels.mondrian.xml',
    jndi: "SampleData",
    query: function(){

    var query = "select NON EMPTY {[Measures].[Sales]} ON COLUMNS,"+
    " NON EMPTY TopCount([Customers].[All Customers].Children, 10.0, [Measures].[Sales]) " +
    " ON ROWS from [SteelWheelsSales]"
    return query;
    }
    }
    };

    var mouseoverFunction = function(){
    var oldColor = $(this).css("color");
    $(this).data("oldColor",oldColor);
    $(this).css("color","red");
    $(this).css("cursor","pointer");
    }

    var mouseoutFunction = function(){
    $(this).css("color",$(this).data("oldColor"));
    $(this).css("cursor","default");
    }

    var clickFunction = function(){
    alert("You clicked on: " + $(this).text())
    }

    var topTenCustomers =
    {
    name: "topTenCustomers",
    type: "tableComponent",
    chartDefinition: MetaLayerHome2.topTenCustomerDefinition,
    htmlObject: "sampleObject",
    executeAtStart: true,
    postExecution: function(){
    var cols = $("#sampleObject td:nth-child(1)");
    cols.die("click");
    cols.die("mouseover");
    cols.die("mouseout");
    cols.live("click",clickFunction);
    cols.live("mouseover",mouseoverFunction);
    cols.live("mouseout",mouseoutFunction);
    }
    };
    Dashboards.init([topTenCustomers]);

  • 相关阅读:
    vue.js引用出错-script代码块放在head和body中的区别
    Notes:一致性哈希算法
    TCP为什么不是两次握手而是三次?
    windows上SSH服务连接远程主机失败
    Centos安装vsftp服务
    使用JavaMail实现发送邮件功能
    在进行javaIO写文件操作后文件内容为空的情况
    Struts2---动态方法调用
    golang的吐槽
    select函数源码阅读
  • 原文地址:https://www.cnblogs.com/iammatthew/p/1803921.html
Copyright © 2020-2023  润新知