dashboard-401089-web-dashboard-integrate-dashboard-component-aspnet-mvc-dashboard-extension-access-to-underlying-widgets.md
Tip
This topic shows the ASP.NET MVC specifics. The main widget customization concepts are described in the following article: Access to Underlying Widgets in DashboardControl.
Most dashboard items use DevExtreme UI widgets to visualize data. Use the DashboardControl‘s API to access these widgets and customize their settings. In ASP.NET MVC, you need to subscribe to the ViewerApiExtension events that allow you to access underlying UI/Data Visualization widgets. For this, handle the ASPxClientDashboard.BeforeRender client-side event, call the ViewerApiExtension.on method and pass the event name as the method’s parameter.
Several dashboard items use built-in components instead of DevExtreme-based UI widgets.
Layout items do not have underlying components.
See the table in the following topic for information about dashboard items and their underlying components: Access to Underlying Widgets in DashboardControl.
The example shows how to customize options of underlying widgets. Handle the onItemWidgetOptionsPrepared event to do the following:
<script src="~/Scripts/WidgetsCustomization.js"></script>
@Html.DevExpress().Dashboard(settings => {
settings.Name = "Dashboard";
settings.ControllerName = "DefaultDashboard";
settings.Width = Unit.Percentage(100);
settings.Height = Unit.Percentage(100);
settings.WorkingMode = DevExpress.DashboardWeb.WorkingMode.Viewer;
settings.ClientSideEvents.BeforeRender = "onBeforeRender";
}).GetHtml()
<script src="~/Scripts/WidgetsCustomization.js"></script>
@Html.DevExpress().Dashboard(Sub(settings)
settings.Name = "Dashboard"
settings.ControllerName = "DefaultDashboard"
settings.Width = Unit.Percentage(100)
settings.Height = Unit.Percentage(100)
settings.WorkingMode = DevExpress.DashboardWeb.WorkingMode.Viewer
settings.ClientSideEvents.BeforeRender = "onBeforeRender"
End Sub).GetHtml()
The following code shows how to customize underlying widgets on the client:
function onBeforeRender(s, e) {
var dashboardControl = s.GetDashboardControl();
var viewerApiExtension = dashboardControl.findExtension('viewerApi');
if (viewerApiExtension) {
viewerApiExtension.on('itemWidgetOptionsPrepared', customizeWidgetOptions);
viewerApiExtension.on('itemWidgetUpdated', customizeWidget);
viewerApiExtension.on('itemWidgetCreated', customizeWidget);
};
}
function customizeWidgetOptions(e) {
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.GridItem) {
e.options.hoverStateEnabled = true
};
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.ChartItem) {
e.options.tooltip.enabled = false;
e.options.animation = {
...e.options.animation,
enabled: true,
duration: 1000
};
e.options.onArgumentAxisClick = function (info) {
info.component.getAllSeries()[0].getPointsByArg(info.argument)[0].showTooltip();
}
};
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.PieItem) {
e.options.legend = {
...e.options.legend,
visible: true,
border: {
...e.options.legend.border,
visible: true
}
};
e.options.animation = {
...e.options.animation,
enabled: true,
duration: 1000
};
}
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.GaugeItem) {
var gaugesCollection = e.dashboardItem.gauges();
gaugesCollection.forEach(element => {
if (element.actualValue().dataMember() == 'Extended Price') {
e.options.scale.tick.tickInterval = 1000
}
});
}
}
function customizeWidget(e) {
if (e.dashboardItem instanceof DevExpress.Dashboard.Model.GaugeItem) {
var gaugesCollection = e.getWidget();
gaugesCollection.forEach(element => {
element.option('scale.label.font.weight', '600');
});
}
}