Search code examples
iccubeiccube-reporting

How to use a static range and display members according a TOP(x) style query


We are trying to add a slider jquery widget, and would like to define a static range, say percentage from 0% to 100%. Then we would like to use the value from the slider in that range as the parameter for the TOP(x), as shown on the picture.

Is this possible? Any hints ?

enter image description here


Solution

  • I've created an example report for you, import it using the default [Sales] schema https://drive.google.com/file/d/0B3kSph_LgXizdk9OdnlTWkxHa1U/view?usp=sharing

    You could achieve this functionality by using the next sequence:

    1. Create Slider widget
    2. Open a widget options dialog and configure widget properties
    3. Select Query Wizard -> Query Type: Mdx Hierarchies
    4. Add single random hierarchy to bypass validation(it will be replaced)
    5. Setup the default value in Initial Selection (i.e. 10%)
    6. Add a code to your report javascript

    viz.filters.Slider.prototype.componentWillMount = function(){
        if(_.isArray(this.props.items)) 
            this.setState({
              entities:new viz.EntityData(this.props.items),
              range:_.map(this.props.defaults,"uniqueName")
            });
    }
    
    viz.filters.Slider.prototype.onBuildAllDone = function(){
        if(!_.isEmpty(this.state.range)) {
            this.fireEvent(vizEventType.onSelection,
                           this.createEvent(this.state.range));
            this.fireEvent(vizEventType.onNewLabel,
                           this.createEvent(this.state.range));
        }
    } 
    
    function consumeEvent( context, event ) {                                
      if (event.name == 'ic3-report-init') { 
        // Following code will replace a data provider for Slider
        // with generated numbers. But to do so, you'll need UID of
        // the Slider widget, in this example it's "w1"
        var widget = event.value.widgetMgr().getItemById("w1");
        _.assign(widget.builder().guts_, {
          items:_.times(100, function(idx){
            return {
              name:idx + 1 + "%", 
              uniqueName:idx + 1
            }
          })})                                          
      }                                                                      
    }