Communication between widgets
The BaseWidget class supports reading or sending data between ArcGIS Web AppBuilder widgets. In the constructor of the BaseWidget class, the publishData, dataFetched, and noData events are subscribed. The BaseWidget class also provides the publishData and fetchData methods.
If you want the widget to publish data, call the publishData method. If you want the widget to receive data from another widget, call the fetchData method, and write code to override the onReceiveData and onNoData methods to read data.
All published data is stored in a data store named DataManager. As a result, the widget can receive published data before it is loaded. For example, widget B wants to read data from widget A. Before widget B is loaded, the data published by widget A is stored in DataManager. When widget B is loaded, it calls the fetchData method to fetch the data from DataManager. After widget B is loaded, it receives all of the published data from widget A. In some cases, you may want to open another widget by calling the this.openWidgetById method before sending the message to it. The following diagram illustrates this workflow:
See the WidgetCommunication sample in the \client\stemapp\widgets\samplewidgets directory of your Web AppBuilder installation.
Note:
Starting at version 2.1, you can pass feature sets between widgets. See Create a feature action in your widget for details.
The method details are described in the following table:
Name | Parameter |
---|---|
publishData | Publishes the data.
|
fetchData | Fetches the data.
|
fetchDataByName | Fetches the data.
|
onReceiveData | Invoked when data is available.
|