0

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

Tincho
  • 71
  • 12

1 Answers1

2

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*/});
  },
}
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
alexP
  • 3,672
  • 7
  • 27
  • 36
  • Thank you, Boghyon!! I have done as you mentioned, and I can catch now any changes done to the selected WBS elements. The problem now is that in the listener I don't know how to trigger a refresh of the chart. I tried doing the following in the listener: var oChart = this.getView("Graph").byId("Graph"); oChart.fireBeforeRebindChart(); But it is throwing an error (is not a function) – Tincho May 07 '21 at 02:33
  • I was able to fire the event, by doing oChart.fireBeforeRebindChart(this.onRebindChart()); But within onRebindChart I need parameter oEvent, which I am not providing when fireing the event. Is there a way to build that parameter? Seems to be related to control sap.ui.base.EventProvider but can't figure out how to use it – Tincho May 07 '21 at 02:52
  • Why you're need oEvent in your `RebindChart` function? You can get the selected items from your list already in the `onSelectWBSElement` method and write it into a local model. So you have all selected items in your `RebindChart` function. Where's the need for having the oEvent from the checkbox event? Btw. it is my answer ;-) – alexP May 07 '21 at 07:17
  • Ohh sorry Alex!! I got confused with the edition done by Boghyon. My bad :). I designed the chart so it is bound to an entity set of the main service. And in rebind I get all selected wbs elems and then use event.filters so to filter the entity set. In case I create a local model, then I would neet to use the customData property, right? haven't gone that road yet. I guess that I would need to collect wbs elems as they get selected. Please wear in mind that listener updateChart will be listening once the view with the chart is called for the first time – Tincho May 07 '21 at 12:28