zoukankan      html  css  js  c++  java
  • 与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]);

  • 相关阅读:
    python定位一组元素并打印出文本
    python+selenium自动化报告HTMLTestRunner增加饼图展示
    PyCharm链接Oracle数据库
    python+selenium自动化鼠标事件之封装
    python学习记录--默认字典defaultdict()
    python学习记录--有序字典OrderedDict()
    python学习记录--Counter()类
    python学习记录--集合
    python学习记录--字典
    python学习记录--列表
  • 原文地址:https://www.cnblogs.com/iammatthew/p/1803921.html
Copyright © 2011-2022 走看看