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. When you want to add your own custom command that can serve for special navigation or when you want to prevent users from selecting options that won’t make sense such as drilling-down on flat data with no hierarchies.

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 (for a developer user). Observe that it has a menu item with the caption Drill Up.

Context menu for a chart
Context menu for a chart

3. Add the script action

Go back to Edit mode and select the chart. Go to its Properties. Scroll down and expand the Context Menu Showing item. Click the plus sign button to add a script action. Enter the following script in 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

3.2. Remove an item from the context menu

This script removes the menu item having the caption Drill Up.

for(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

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.
500-250 Ferrand Drive
Toronto, ON, Canada
M3C 3G8

North America: 1.800.463.1492
International: 1.416.467.5100

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