customizeContextMenu(customizeFunction: Function)
[starting from version: 2.6]
This API call allows customizing the context menu. For example, you can create a context menu for the flat form or remove all context menu items for the classic (tabular) form. Learn more in this guide: Customizing the context menu.
customizeContextMenu
can be defined in two ways:
pivot.customizeContextMenu(customizeFunction: Function)
.new Flexmonster({customizeContextMenu: customizeFunction, ...})
.The customizeFunction
function. It has the following signature: customizeFunction(items: ContextMenuItemObject[], data: CellDataObject | CellDataObject[] | ChartDataObject, viewType: String): ContextMenuItemObject[]
.
Data passed to the customizeFunction
:
Parameter/Type | Description |
---|---|
items ContextMenuItemObject[] | Context menu items created by Flexmonster. |
data CellDataObject | CellDataObject[] | ChartDataObject | Contains information about the right-clicked element. If a grid cell is right-clicked, the data is a CellDataObject containing information about the cell.If multiple cells are selected and then right-clicked, the data is an array of CellDataObjects.If a chart element is right-clicked, the data is a ChartDataObject containing information about the chart segment. |
viewType String | View type that was right-clicked. Can have one of the four possible values:
|
The customizeFunction
must return items
, the array of new or changed context menu items. If items
is null
, the default items
will be used. If items
is []
, the context menu will be hidden.
Property/Type | Description |
---|---|
id String | The ID of the menu item. |
label String | The name of the menu item. |
handler Function | The function that handles clicks on this item. |
submenu ContextMenuItemObject[] | optional Contains submenu items. |
isSelected Boolean | optional Specifies whether the menu item is selected. |
class String | optional Adds a custom CSS class to the specified item. |
1) Add a Switch to charts item to the flat table context menu:
pivot.customizeContextMenu(function(items, data, viewType) {
if (viewType == "flat")
items.push({
label: "Switch to charts",
handler: function() {
pivot.showCharts();
}
});
return items;
});
2) Remove the Aggregation item from all the context menus:
function customizeContextMenuFunction(items, data, viewType) {
items = items.filter(function(item) {
return item.label !== "Aggregation"
});
return items;
}
Customizing the context menu
customizeCell()
customizeChartElement()