Modify context menu using script
1. Overview
Dundas BI offers a built-in context menu (AKA right-click menu) for all visualizations. This menu is mostly used for built-in interactions such as drill down/up, filter, re-visualize etc.
While in most use cases, there is no need to modify the default context menu, there are cases where adding or limiting options can improve the user experience. For example, you may want to add your own custom command to add special navigation, or prevent users from drilling-down on flat data with no hierarchies.
Script Library sample: Customize the context menu
2. Setup
For this example, create a new dashboard and add a chart to it.
Switch to View mode and right-click on the chart to see its original context menu. Observe that it has a menu item with the caption Drill Up.
3. Add the script action
Go back to Edit mode and select the chart. Open the Properties window. Scroll down to the Actions section and expand the Context Menu Showing item. Click the + button to add a script action. Enter script like the following into the Script Editor.
3.1. Add an item to the context menu
This script adds a menu item with the caption New Item.
var cmdObj = new dundas.Command({ caption: "New Item", categoryName: "myItem", action: function() { //handle click event window.location.assign("http://www.dundas.com/support/") }.bind(this), isEnabled: true }); // Add command to command list. e.originalEvent.commands.push(cmdObj);
This script creates a new dundas.Command object.
3.2. Remove an item from the context menu
This script removes the menu item with the caption Drill Up.
for (var i = 0; i < e.originalEvent.commands.length; i++) { if (e.originalEvent.commands[i].caption == "GS_ContextMenu_DrillUp".localize()) { e.originalEvent.commands.splice(i, 1); break; } }
The text GS_ContextMenu_DrillUp is a localized string key, which could be replaced by different text depending on the language of the user viewing the dashboard. For details on finding other localized string keys, see Localization and Multi-Language Support.
3.3. View the dashboard
Test the script by switching to View mode. Observe the modified menu by right-clicking on the chart to see its context menu.