Category / Section
How to add a Custom Menu Item to the Widget's Option Menu?
Published:
This article will explain how to add a custom menu item to a widget’s option menu and configure its functionality using JavaScript embedding. This can be achieved with the help of two events: widgetSettings.beforeWidgetControlMenuOpen
and widgetSettings.onWidgetControlMenuClick
.
Steps to Add Custom Menu Item
- In the
BoldBI.create()
method of the embedded application, add thewidgetSettings
API member. Initialize the eventbeforeWidgetControlMenuOpen
to add a new menu item through thecreateNewOption
function call. Also, initialize the eventonWidgetControlMenuClick
to trigger a defined action through thewidgetIconClick
function call.
function renderDashboard() {
this.dashboard = BoldBI.create({
serverUrl: rootUrl + "/"+siteIdentifier,
dashboardId: dashboardId,
embedContainerId: "dashboard",
embedType: BoldBI.EmbedType.Component,
mode: BoldBI.Mode.View,
environment: environment == "enterprise" ? BoldBI.Environment.Enterprise : BoldBI.Environment.Cloud,
width: "100%",
height: "100%",
expirationTime: 100000,
authorizationServer: {
url: authorizationServerUrl
},
widgetSettings: {
beforeWidgetControlMenuOpen: "createNewOption",
onWidgetControlMenuClick:"widgetIconClick",
}
});
this.dashboard.loadDashboard();
};
- Include code to add a new menu item in a particular widget (mention the name of the widget), under
createNewOption
function and code to trigger action on click, underwidgetIconClick
function as shown in the following code snippet.
function createNewOption(arg) {
if(arg.header =="Average Treatment Cost By Age Group"){ //Provide the widget name where you want to add the new option.
var newOption= { id: 'NewItem', text: 'NewItem', parentId: null, sprite: 'su su-group' };
arg.menuItems.push(newOption);
}
}
function widgetIconClick(args) {
//Extract the required value.
}
The output in the dashboard widget will look like the image below.