Table of contents

customizeContextMenu

customizeContextMenu(customizeFunction:Function)

[starting from version: 2.6]

This API call allows customizing context menu. For example, you can create context menu for a flat table or remove all context menu items for classic view.

customizeContextMenu can be defined in two ways:

  1. as a regular API call: flexmonster.customizeContextMenu(customizeFunction:Function);
  2. as an initialization parameter: new Flexmonster({customizeContextMenu: customizeFunction, ...})

Parameters

Data passed to the customizeFunction:

  • items – Array of objects. Context menu items created by Flexmonster. Each object can have the following properties:
    • label – String. The name of the menu item.
    • handler – Function|String. The function or the name of the function that handles click on this item.
    • submenu (optional) – Array of objects. Array of submenu items. Each submenu item has the same structure as items.
    • isSelected (optional) – Boolean. Specifies whether the menu item is selected.
  • data – Object. Information about the right-clicked object. In case of right click on the grid, this is a Cell Data Object containing information about the cell. In case of right click on the chart element, this is a Chart Data Object containing information about the chart segment.
  • viewType – String. View type that was right-clicked. Can have one of the four possible values:
    1. "pivot" – Means that pivot grid was right-clicked, either compact or classic view.
    2. "flat" – Means that flat table view was right-clicked.
    3. "charts" – Means that charts view was right-clicked.
    4. "drillthrough" – Means that drill through view was right-clicked.

Returns

items, the array of new or changed context menu items. If items is null, the default items will be used. If items is [], context menu will be hidden.

Examples

1) Add to flat table context menu “Switch to charts” option:

flexmonster.customizeContextMenu(function(items, data, viewType) {
	if (viewType == "flat") 
		items.push({
			label: "Switch to charts",
			handler: function() {
				flexmonster.showCharts();
			}
		});
	return items;
});

Open the example on JSFiddle.

2) Remove “Aggregation” item from all context menus:

flexmonster.customizeContextMenu(function(items, data, viewType) {
	items = items.filter(function (item){
				return item.label !== "Aggregation"
			})
	return items;
});