Example T1049664
Visible to All Users

XAF - Open a Detail View When a Grid Row is Clicked in the Dashboard (Blazor)

This example demonstrates how to invoke a Detail View when a user clicks a row in GridDashboardItem. In the invoked Detail View, a user can view or edit a business object corresponding to the clicked row.

chrome_nGcK0qFdu4

Implementation Details

See the following help topic for more information: Open a Detail View When the Grid Row is Clicked in the Dashboard (Blazor)

Files to Look At

Documentation

More Examples

How to open DetailView by clicking a grid row in the integrated Dashboard (WinForms and ASP.NET Web Forms)

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

EF/OpenViewFromDashboardEF/OpenViewFromDashboardEF.Blazor.Server/wwwroot/js/customScript.js
JavaScript
"use strict"; globalThis.customScript = { showDetailViewControllers: {}, onBeforeRender: function (dashboardControl) { const viewerApi = dashboardControl.findExtension("viewerApi"); viewerApi.on("itemClick", globalThis.customScript.processItemClick.bind(dashboardControl)); }, registerController: function (key, controller) { globalThis.customScript.showDetailViewControllers[key] = controller; }, unregisterController: function (key) { delete globalThis.customScript.showDetailViewControllers[key]; }, processItemClick: function (args) { const itemData = args.getData(), dataSlice = itemData.getSlice(args.getAxisPoint()), oidMeasure = dataSlice.getMeasures().find((measure) => measure.dataMember === 'ID').id, measureValue = dataSlice.getMeasureValue(oidMeasure), objectId = measureValue.getValue(), controllerId = this.element().dataset["showdetailid"]; globalThis.customScript.showDetailViewControllers[controllerId].invokeMethodAsync("ShowDetailView", objectId); } } if (!globalThis.xafBlazorDashboardUserScripts) { globalThis.xafBlazorDashboardUserScripts = []; } globalThis.xafBlazorDashboardUserScripts.push(globalThis.customScript);
EF/OpenViewFromDashboardEF/OpenViewFromDashboardEF.Blazor.Server/Controllers/BlazorShowDetailViewFromDashboardController.cs
C#
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Dashboards.Blazor.Components; using DevExpress.Persistent.Base; using OpenViewFromDashboardEF.Module.BusinessObjects; using Microsoft.JSInterop; namespace OpenViewFromDashboard.Blazor.Server.Controllers; public class BlazorShowDetailViewFromDashboardController : ObjectViewController<DetailView, IDashboardData> { private string clientId = Guid.NewGuid().ToString(); private DotNetObjectReference<BlazorShowDetailViewFromDashboardController> controllerReference; public BlazorShowDetailViewFromDashboardController() { controllerReference = DotNetObjectReference.Create(this); } protected override void OnActivated() { base.OnActivated(); Application.ServiceProvider.GetRequiredService<IJSRuntime>().InvokeVoidAsync("customScript.registerController", clientId, controllerReference).Preserve(); View.CustomizeViewItemControl<BlazorDashboardViewerViewItem>(this, CustomizeDashboardViewerViewItem); } private void CustomizeDashboardViewerViewItem(BlazorDashboardViewerViewItem dashboardViewerViewItem) { dashboardViewerViewItem.ComponentModel.SetAttribute("data-showdetailid", clientId); } protected override void OnDeactivated() { Application.ServiceProvider.GetRequiredService<IJSRuntime>().InvokeVoidAsync("customScript.unregisterController", clientId).Preserve(); base.OnDeactivated(); } protected override void Dispose(bool disposing) { base.Dispose(disposing); controllerReference.Dispose(); } [JSInvokable] public void ShowDetailView(string oidString) { if(!Guid.TryParse(oidString, out var id)) { return; } var objectSpace = Application.CreateObjectSpace(typeof(Contact)); var item = objectSpace.FirstOrDefault<Contact>(c => c.ID == id); if(item is not null) { var detailView = Application.CreateDetailView(objectSpace, item, true); Application.ShowViewStrategy.ShowViewFromCommonView(detailView); } else { objectSpace.Dispose(); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.