Modify context menu using script

Contents[Hide]

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.

Note
Context menu options can also be removed by disabling view functionality.

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.

Context menu for a chart (dashboard checked-out)
Context menu for a chart (dashboard checked-out)

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);

Add a script to add a menu item
Add a script to add a menu item

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;
    }
}

Add a script to remove a menu item
Add a script to remove a menu item

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. 

View the dashboard with Drill Up removed from the context menu
View the dashboard with Drill Up removed from the context menu

View the dashboard with New Item added to the context menu
View the dashboard with New Item added to the context menu

4. See also

Dundas Data Visualization, Inc.
400-15 Gervais Drive
Toronto, ON, Canada
M3C 1Y8

North America: 1.800.463.1492
International: 1.416.467.5100

Dundas Support Hours:
Phone: 9am-6pm, ET, Mon-Fri
Email: 7am-6pm, ET, Mon-Fri