In my web application I am able to add widgets and also change the rights of widgets from confing.json file,But this change is permanently. And I want the property of the widget to be enabled or disabled programatically at the run time using java-script API.Please suggest how to do it.
Asked
Active
Viewed 391 times
1 Answers
0
It's possible. Just publish an appConfig object with the new configuration using the appConfigChanged event name.
Here is a sample code that you could paste in chrome console to see it working with your Web AppBuilder project:
var topic = require('dojo/topic')
function showWidget(widgetId, trueOrFalse) {
var appConfig = getAppConfig();
var widgetsFound = appConfig.widgetPool.widgets.filter( widget => widget.id === widgetId );
if(widgetsFound.length > 1){
throw Error('More than 1 widget with the same id ' + widgetsFound[0].id + '. ');
}
if(widgetsFound.length == 1){
var widget = widgetsFound[0];
widget.visible = trueOrFalse;
topic.publish("appConfigChanged", appConfig, 'attributeChange', {});
}
}
And then call:
showWidget(yourWidgetId, false);

Carlos Nantes
- 1,197
- 1
- 12
- 23
-
Thank you for reply. Can you please tell which file to add this code in my web application – Shalinee Mishra May 16 '20 at 09:17