SpreadsheetSettings.CustomActionRouteValues Property
Defines the custom callback routing logic by specifying the names of a Controller and an Action which should handle custom callbacks initiated by the ASPxClientSpreadsheet.PerformCallback method.
Namespace: DevExpress.Web.Mvc
Assembly: DevExpress.Web.Mvc5.v24.1.dll
NuGet Package: DevExpress.Web.Mvc5
Declaration
Property Value
Type | Description |
---|---|
Object | An object containing the Controller and Action names. |
Remarks
Use the client ASPxClientSpreadsheet.PerformCallback method if you need to dynamically update the Spreadsheet by asynchronously going to the server (using AJAX-based callback technology) and perform server-side processing in the specified Action. Via the method’s data parameter, you can pass any information collected on the client to the server for further server processing.
The client PerformCallback method posts back to the server using the callback technology and is handled in an Action specified by the CustomActionRouteValues property. Any data passed via the method’s data parameter can be accessed on the server as a parameter of the specified Action. So, the necessary server-side actions can be performed in the handling Action based upon the value(s) passed from the client.
Example: How to modify a document
This example demonstrates how to modify a document in the Spreadsheet extension. The main idea of this approach is to perform a callback using the PerformCallback(parameter) method and modify a document in the CustomActionRouteValues
action.
@Html.DevExpress().Spreadsheet(settings => {
settings.Name = "Spreadsheet";
settings.CallbackRouteValues = new { Controller = "Home", Action = "SpreadsheetPartial" };
settings.CustomActionRouteValues = new { Controller = "Home", Action = "CustomAction" };
settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
settings.Height = 500;
settings.ReadOnly = false;
settings.WorkDirectory = "~/Docs";
settings.RibbonMode = SpreadsheetRibbonMode.Ribbon;
}).Open(Server.MapPath("~/Docs/testDocument1.xlsx")).GetHtml()
<script>
function OnCommandExecuted(s, e) {
var command = e.item.name;
Spreadsheet.PerformCallback({ customCommand: command })
}
</script>
@Html.DevExpress().Ribbon(settings => {
settings.Name = "Ribbon";
settings.ShowFileTab = false;
settings.ShowTabs = false;
settings.OneLineMode = true;
settings.ClientSideEvents.CommandExecuted = "OnCommandExecuted";
var group = settings.Tabs.Add("Home").Groups.Add("Group 0");
group.Items.Add(MVCxRibbonItemType.ButtonItem, i => {
i.Text = "Apply formatting";
i.Name = "applyFormatting";
((RibbonButtonItem)i).LargeImage.IconID = IconID.ActionsNew32x32;
});
group.Items.Add(MVCxRibbonItemType.ButtonItem, i => {
i.Text = "Insert link";
i.Name = "insertLink";
i.Size = RibbonItemSize.Small;
});
group.Items.Add(MVCxRibbonItemType.ButtonItem, i => {
i.Text = "Draw Borders";
i.Name = "drawBorders";
i.Size = RibbonItemSize.Small;
});
group.Items.Add(MVCxRibbonItemType.ButtonItem, i => {
i.Text = "Show total";
i.Name = "showTotal";
i.Size = RibbonItemSize.Small;
});
}).GetHtml()
@using (Html.BeginForm()) {
@Html.Action("SpreadsheetPartial")
}
public ActionResult Index() {
return View();
}
public ActionResult SpreadsheetPartial() {
return PartialView("_SpreadsheetPartial");
}
public ActionResult CustomAction(string customCommand) {
IWorkbook workbook = SpreadsheetExtension.GetCurrentDocument("Spreadsheet");
Worksheet worksheet = workbook.Worksheets[0];
switch (customCommand) {
case "applyFormatting":
CellRange priceRange = worksheet.Range["C2:C15"];
Formatting rangeFormatting = priceRange.BeginUpdateFormatting();
rangeFormatting.Font.Color = Color.SandyBrown;
rangeFormatting.Font.FontStyle = SpreadsheetFontStyle.Bold;
rangeFormatting.Fill.BackgroundColor = Color.PaleGoldenrod;
rangeFormatting.NumberFormat = "$0.0#";
rangeFormatting.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
rangeFormatting.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
priceRange.EndUpdateFormatting(rangeFormatting);
break;
case "insertLink":
worksheet.Columns["G"].WidthInPixels = 180;
Cell cell1 = worksheet.Cells["G4"];
cell1.Fill.BackgroundColor = Color.WhiteSmoke;
worksheet.Hyperlinks.Add(cell1, "https://documentation.devexpress.com/OfficeFileAPI/14912/Spreadsheet-Document-API", true, "Spreadsheet Document API");
break;
case "drawBorders":
CellRange tableRange = worksheet.Range["A2:E16"];
tableRange.Borders.SetAllBorders(Color.RosyBrown, BorderLineStyle.Hair);
break;
case "showTotal":
Cell cell2 = worksheet.Cells["E16"];
cell2.Formula = "=SUBTOTAL(9,E2:E15)";
Cell cell3 = worksheet.Cells["A16"];
cell3.Formula = "SUBTOTAL(103,A2:A15)";
Cell cell4 = worksheet.Cells["D16"];
cell4.Value = "Total amount";
break;
}
return SpreadsheetExtension.GetCustomActionResult("Spreadsheet");
}