Search code examples
bindingsapui5master-detail

Rebind Smart Chart, or refresh it


I have created a Master-Detail app, with three columns. First view is to select a Project. Second view, to select WBS Elements. Third view, it has a Smart Chart based on the selected WBS from second view. So far, the first time the chart is triggered it works fine. Problem is when I deselect a few WBS, and select new ones. I can't find a way to either rebind the chart nor to refresh the third view (so either the onInit or onBeforeRendering gets triggered again)

Chart currently is getting created once user hits the emphasized chart button at the top of the second view. Please do not pay attention to the layout of the second view, it is still under development.

Hope you can help me finding a way to refresh the chart after changes on the selected WBS.

Regards, Tincho

enter image description here


Solution

  • You could use the EventBus. After loading the Chart View first time, the EventBus is "listening". Every time you're de/selecting a checkbox the event is triggered.

    { // Chart view controller
      onInit: function() {
        this.oEventBus = this.getOwnerComponent().getEventBus();
        this.oEventBus.subscribe("Checkbox", "Selected", this.updateChart); // "Listener"
      },
      updateChart: function(channelId, eventId, data) {
        // ...
      },
    }
    
    { // WBS view controller
      onSelectWBSElement: function(oEvent) {
        const oEventBus = this.getOwnerComponent().getEventBus();
        oEventBus.publish("Checkbox", "Selected", {/*data*/});
      },
    }