Back to Devexpress

ASPxClientSpreadsheetPopupMenuItem Class

aspnet-js-aspxclientspreadsheetpopupmenuitem.md

latest4.4 KB
Original Source

ASPxClientSpreadsheetPopupMenuItem Class

Represents an individual item of the Spreadsheet’s context menu.

Declaration

ts
declare class ASPxClientSpreadsheetPopupMenuItem

Remarks

The ASPxClientSpreadsheetPopupMenuItem object contains settings that fully define a context menu item.

See Online Demo: Context Menu Customization

Example

This sample illustrates how to prevent the context menu display for worksheet tabs and to add a custom menu item to the context menu displayed for row headings.

The context menu is dynamically processed in the ASPxClientSpreadsheet.PopupMenuShowing client event. The current context menu type is determined through the ASPxClientSpreadsheetPopupMenuShowingEventArgs.menuType property. A custom menu item is implemented as a new item containing a custom command name.

Clicks on the custom menu item with the custom command name are processed by using the ASPxClientSpreadsheet.CustomCommandExecuted client event. Within its handler, the activated custom command is identified and the corresponding action (insertion of a row with the current date and time values) is performed through a callback to the server.

csharp
using DevExpress.Spreadsheet;
using DevExpress.Web;
using DevExpress.Web.ASPxSpreadsheet;
using DevExpress.Web.ASPxSpreadsheet.Internal;
using DevExpress.Web.Office;
using DevExpress.Web.Office.Internal;

...
    protected void Page_Load(object sender, EventArgs e) {
        if(!Page.IsPostBack) {
            string filePath = Server.MapPath("~/App_Data/WorkDirectory/DayBook.xlsx");
            spreadsheet.Open(filePath);
        }
    }

    protected void spreadsheet_Callback(object sender, CallbackEventArgsBase e) {
        IWorkbook currentWorkbook = spreadsheet.Document;
        Worksheet currentWorksheet = currentWorkbook.Worksheets.ActiveWorksheet;
        currentWorkbook.BeginUpdate();
        currentWorksheet.InsertCells(currentWorksheet.Selection, InsertCellsMode.EntireRow);
        FillInTemplateValues(currentWorksheet);
        currentWorkbook.EndUpdate();
    }

    void FillInTemplateValues(Worksheet currentWorksheet) {
        int currentRowIndex = currentWorksheet.Selection.TopRowIndex;
        currentWorksheet.Cells[currentRowIndex, 1].Value = DateTime.Now.Date;
        currentWorksheet.Cells[currentRowIndex, 2].Value = DateTime.Now.TimeOfDay;
        currentWorksheet.Cells[currentRowIndex, 2].NumberFormat = "h:mm";
    }
aspx
<head runat="server">
    <script type="text/javascript">
        function SpreadsheetPopupMenuShowing(s, e) {
            // Disable the context menu for sheet tabs
            if(e.menuType === ASPxClientSpreadsheetPopupMenuType.SheetTab)
                e.cancel = true;
            // Add a custom menu item for the row heading context menu
            else if(e.menuType == ASPxClientSpreadsheetPopupMenuType.RowHeading) {
                var item = new ASPxClientSpreadsheetPopupMenuItem("InsertRowByTemplate", "Insert Row By Template", null, null);
                e.menuItems.Add(item);
            }
        }
        function SpreadsheetCustomCommandExecuted(s, e) {
            if(e.commandName === "InsertRowByTemplate")
                spreadsheet.PerformCallback();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <dx:ASPxSpreadsheet runat="server" ID="spreadsheet" ClientInstanceName="spreadsheet"
            WorkDirectory="~/App_Data/WorkDirectory" ShowConfirmOnLosingChanges="false"
            OnCallback="spreadsheet_Callback">
            <ClientSideEvents 
                PopupMenuShowing="function(s, e) { SpreadsheetPopupMenuShowing(s, e); }" 
                CustomCommandExecuted="function(s, e) { SpreadsheetCustomCommandExecuted(s, e); }" />
        </dx:ASPxSpreadsheet>
    </div>
    </form>
</body>

See Also

Online Demo: Context Menu Customization

ASPxClientSpreadsheetPopupMenuItem Members