Select to view content in your preferred language

Open widget in Widget Controller

3488
11
Jump to solution
09-29-2021 12:46 AM
MatejKutik
Occasional Contributor

Hello everyone!

 

I'm trying to programmatically open widget that is in "Widget Controller".

I have tried

WidgetManager.getInstance().openWidget(widgetId)

and

const action = appActions.openWidget(widgetId);
getAppStore().dispatch(action);

 

Both attempts opened the widget, but only when the widget had been previously opened.

Is there a way how to open widget that was not yet opened?

 

I'm using ArcGIS Experience Builder Developer Edition version 1.5.

 

Thanks, Matěj. 

11 Replies
JeffreyThompson2
MVP Frequent Contributor

@TimWestern Everything you have said above is accurate, but it is possible to make it so that the widget_id numbers can be altered in the Settings panel. When I designed my Identify Widget, I built it with the intent that it would be used in a Sidebar Widget and that it would automatically open and close it. But, I made the widget id number a variable, so that it could be used in multiple projects by multiple developers by just finding the number and changing it in the Settings Panel. My code for closing the Sidebar looks like this:

getAppStore().dispatch(appActions.widgetStatePropChange(`widget_${sidebarId}`, 'collapse', false))
GIS Developer
City of Arlington, Texas
TimWestern
MVP

yeah, creating a setting to control that ID could work great too.  I think I didn't adopt that for my more complex example in part because I was having issues getting that setting in the action when it was constructed and called from another widget.  next time I work on one of these I'll look into that, cause ideally, there are probably a lot of cases where you'd want it to work just like that.  Thanks for pointing that out. (Also my approach presumes only one version of the widget on a page, if its used more than once, the code I shared won't get it for all of them)

(IIRC, I was having issues keeping that widgetID known and present if that widget was not currently open and loaded on the screen, it occurred to me later, that saving that ID somewhere with more clear scope (such as to appStore itself) could have solved that also.)

0 Kudos