Calling a function from another widget

7104
4
01-13-2015 01:40 AM
NEvatt
by
New Contributor III

Hello,

Does anyone know how to call a function from a seperate widget?  I have created a simple search tool, which will run a query, and return graphic results on the map.  But I also want these results to display in a different custom table app.  I can pass the results to the infowindow features: this.map.infoWindow.setFeatures(features);  which is fine, but I have no way telling the table app to now display the results.

The best way I can think of is using some arbitrary map event listener (see here).  Something like 'update-end' and have that listener registered in my table app.  But obviously, the best way would be to simply call the function.

There are also the publishData and fetchData methods which are very briefly described here 'Communitcation between widgets', but I am not sure how I am supposed to use them.

Anyone had this issue before?

thanks,

Nat

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

N Evatt,

  I don't have any examples yet but you can see the testing module that esri used for the datamanager by going to client\stemapp\jimu.js\tests\test-datamanager.

There is some doh/runner stuff that can get confusing but if you just focus on the publishData and fetchData stuff you can get a pretty good idea. One of the really great things is that you can have your second widget use the listenWidgetIds property and it will listen for publishData calls from your widgetA

      //listenWidgetIds: String[]

      //    app use this property to filter data message, if not set, all message will be received.

      //    this property can be set in config.json

      //About the communication between widgets:

      //  * Two widgets can communicate each other directly, or transferred by DataManager.

      //  * If you want to share data, please call *publishData*. the published data will

      //    be stored in DataManager.

      //  * If you want to read share data, you can override *onReceiveData* method. Whenever

      //    any widget publishes data, this method will be invoked. (communication directly)

      //  * If you want to read the data that published before your widget loaded, you can call

      //    *fetchData* method and get data in *onReceiveData* method. If the data contains

      //    history data, it will be availble in *historyData* parameter.

      //      (transferred by DataManager)

NEvatt
by
New Contributor III

Hi Robert,

Thanks for that, very helpful.

Using your advice, what I ended up doing was using the publishData function, so "this.publishData" within my widget (widget_a) and then within the  BaseWidget.js file, in _onReceiveData function, I have an if then statement to target the correct widget by name (this.name - widget_b), change a property in widget_b, then run the startup function in widget_b (this.startup()), which looks at the changed property and fires off the correct function.

I am sure this is not the most elegant way of doing it, but I couldn't figure out how to trigger a function simply from the listenWidgetsId property change value.  I am open to a better solution than this, but in the time being this method might help someone with the same issue.

Thanks,

Nat

CraigPrisland2
New Contributor III

Robert,

 

I have a similar question that I am trying to work my way through.  I have been looking through the communication between widgets post from above but haven't been able to successfully accomplish what I am working on.  What I am trying to accomplish is the following:  I have a geoprocessing service that I am using in a geoprocessing widget which concatenates several address fields (i.e. house number, street pre dir, street name, etc..) into one full address field.  I also have a custom "Reporting" widget which uses this full address field (as well as others) and creates a PDF.  Currently my workflow consists of the user having to first run the geoprocessing widget (there are no user inputs in this widget so I added the "this._onExecuteClick():" syntax to auto-execute when the user clicks on the widget) and then have to run the Reporting widget.  What I am trying to accomplish is not having the user to first click on the geoprocessing widget and have syntax in the Reporting widget where it would first call and run geoprocessing widget before running the Reporting widget.  Any assistance would be greatly appreciated.

 

I am using the Tab Theme in WAB Dev 2.6

 

Thanks,

Craig

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Craig,

   Start a new thread for this.

0 Kudos