PopupMenuItemCollection Class

A collection of items in the Spreadsheet’s context menu.

Declaration

class PopupMenuItemCollection
See Also

Methods

add(item) Method

Adds the specified menu item to the end of the collection.

Declaration

add(
    item: PopupMenuItem
): void

Parameters

Name Type Description
item PopupMenuItem

The item to be added to the collection.

Remarks

For a full example, see Context Menu Customization demo.

function addCustomMenuItem(menuItems, command) {
     var item = new PopupMenuItem(command.name, command.text, null, null);
     menuItems.Add(item);
}

clear Method

Removes all menu items from the collection.

Declaration

clear(): void

Remarks

For a full example, see Context Menu Customization demo.

function SpreadsheetPopupMenuShowing(s, e) {
    if (e.menuType === PopupMenuType.Cell) {
        e.menuItems.Clear();
        if (needToAddCustomMenuItems(s)) {
            if (isSelectedCellOfType(s, currencyColumns))
                addCustomMenuItem(e.menuItems, convertCurrencyCommand);
            if (isSelectedCellOfType(s, discountColumns))
                addCustomMenuItem(e.menuItems, discountCommand);
            if (isSelectedCellOfType(s, weightColumns))
                addCustomMenuItem(e.menuItems, convertUnitsCommand);
        }
    }
    else if (e.menuType !== PopupMenuType.AutoFilter)
        e.cancel = true;
}

get(index) Method

Returns a menu item specified by its index in the collection.

Declaration

get(
    index: number
): PopupMenuItem

Parameters

Name Type Description
index number

The zero-based index of the item.

Returns

Type Description
PopupMenuItem

An object that is a menu item with the specified index.

getByName(name) Method

Gets an item specified by its name.

Declaration

getByName(
    name: string
): PopupMenuItem

Parameters

Name Type Description
name string

The name property value of a menu item.

Returns

Type Description
PopupMenuItem

An item with the specified name.

getCount Method

Returns the total number of menu items in the collection.

Declaration

getCount(): number

Returns

Type Description
number

The total number of menu items.

insert(index, item) Method

Adds the specified item to the specified position within the collection.

Declaration

insert(
    index: number,
    item: PopupMenuItem
): void

Parameters

Name Type Description
index number

The zero-based index at which the specified item should be inserted.

item PopupMenuItem

An item to insert.

remove(index) Method

Removes a menu item specified by its index within the collection.

Declaration

remove(
    index: number
): void

Parameters

Name Type Description
index number

The index of the menu item

removeByName(name) Method

Removes a menu item specified by its name.

Declaration

removeByName(
    name: string
): void

Parameters

Name Type Description
name string

The name property value of a menu item.