Your search did not match any results.

Context Menu Customization

This demo shows how to implement a custom context menu and display it for specified sheet cells only.

To populate the context menu with custom items, write the SpreadsheetPopupMenuShowing event handler. You can add different items to the menu based on the cell data type (such as weight, currency, or discount values). Use the SpreadsheetCustomCommandExecuted event to process an item click. The commandName event argument allows you to identify the clicked item.

@inject IHostingEnvironment env <script src="~/ContextMenuCustomization.js" asp-append-version="true"></script> <div id="popoverContainer" class="custom-popover"> </div> @{ var documentPath = System.IO.Path.Combine( env.ContentRootPath, DirectoryManagmentUtils.GetDocumentSampleFolderPath(Context), "ContextMenu.xlsx"); } @(Html.DevExpress() .Spreadsheet("spreadsheet") .Height("500px") .Width("100%") .ConfirmOnLosingChanges(confirm => confirm.Enabled(false)) .DocumentRequestHandlerUrl(Url.Action("DxDocumentRequest")) .Open(documentPath) .ClientSideEvents(events => { events.OnPopupMenuShowing("SpreadsheetPopupMenuShowing"); events.OnCustomCommandExecuted("SpreadsheetCustomCommandExecuted"); }) ) <script> $("#popoverContainer").dxPopover({ position: "right", maxWidth: 230 }); function getContextMenuCustomData(onSuccess) { var spreadsheetState = spreadsheet.getSpreadsheetState(); $.ajax({ type: 'POST', url: '@Url.Action("GetContextMenuCustomData")', data: { spreadsheetState: spreadsheetState, rowIndex: spreadsheet.getSelection().activeCellRowIndex }, success:function(data) { onSuccess(data); } }); } </script>
using DevExpress.AspNetCore.Spreadsheet; using DevExpress.Spreadsheet; using DevExpress.XtraSpreadsheet.Export; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using System; using System.IO; using System.Linq; using System.Text; namespace AspNetCoreDemos.Spreadsheet { [Route("[action]")] public class DemosController : Controller { public ActionResult ContextMenuCustomization() { return View(); } [HttpPost] public IActionResult GetContextMenuCustomData(SpreadsheetClientState spreadsheetState, int rowIndex) { var spreadsheet = SpreadsheetRequestProcessor.GetSpreadsheetFromState(spreadsheetState); Worksheet activeWorksheet = spreadsheet.Document.Worksheets.ActiveWorksheet; rowIndex = rowIndex + 1; Range discountInfoRange = activeWorksheet.Range["J" + rowIndex + ":N" + rowIndex]; string resultFormat = "{0} to {4} units - {1}, <br /> {2} units or more - {3}"; string[] cellValues = discountInfoRange.ExistingCells.Select((c, index) => (index % 2 == 0) ? c.Value.ToString() : c.DisplayText).ToArray(); return Ok(string.Format(resultFormat, cellValues)); } } }