Access to Underlying Widgets
- 3 minutes to read
The Web Dashboard control uses DevExtreme widgets to visualize dashboard items’ data. You can access these widgets and customize their settings to add specific capabilities.
The DashboardControl exposes the following events that allow you to access these widgets and customize their settings:
- The ViewerApiExtensionOptions.onItemWidgetCreated property raises the ItemWidgetCreated event once for each widget when the dashboard is loaded to client. Handle this event to subscribe to events of the underlying widget.
ViewerApiExtensionOptions.onItemWidgetUpdating/ViewerApiExtensionOptions.onItemWidgetUpdated properties raises the ItemWidgetUpdating/ItemWidgetUpdated events when the client widget needs to be updated. For instance, this can be when you apply a master filter or change parameter values.
Use the ViewerApiExtensionOptions.onItemWidgetUpdating property to unsubscribe from the client widget’s events. The ViewerApiExtensionOptions.onItemWidgetUpdated property is used to customize widgets. This allows you to prevent the DashboardControl from rewriting customized options.
The ItemWidgetEventArgs.itemName event parameter returns the name of the dashboard item whose widget can be customized. Use the ItemWidgetEventArgs.getWidget method to access the corresponding underlying widget.
The following table lists dashboard items whose underlying widgets can be accessed when you handle the ItemWidget… events:
Dashboard Item | Underlying Widget(s) |
---|---|
an array of dxPieChart widgets | |
an array of dxCircularGauge or dxLinearGauge widgets | |
dxTreeView (for v17.1 and earlier) | |
n/a See Note 1 | |
n/a See Note 1 | |
n/a See Note 2 |
1 The content of the TextBoxDashboardItem and the ImageDashboardItem is an HTML element wrapped in a jQuery object.
2 The CustomDashboardItem is a custom widget. You can customize it directly.
Limitations
Do not change the following settings to avoid possible issues:
- data binding settings;
- basic data presentation settings (for instance, a set of grid columns or chart series).
Note that changes made with the ItemWidget… events do not change the dashboard/dashboard items’ appearance in exported documents.
Example
This example demonstrates how to customize client widgets used to visualize data within dashboard items at runtime using DashboardControl‘s API. The following options are changed:
- The hovered grid row is highlighted in the underlying dxDataGrid in the ItemWidgetCreated event handler.
- A standard tooltip in the dxChart‘s series point is disabled. Click the required label on the argument axis to invoke a tooltip. The ItemWidgetUpdated and ItemWidgetUpdating event are used to subscribe and unsubscribe to/from the argumentAxisClick event.
- A pie legend is shown for the underlying dxPieChart.
@page
<div style="position: absolute; left: 0; top: 0; right: 0; bottom: 0;">
@(Html.DevExpress().Dashboard("dashboardControl1")
.Width("100%")
.Height("100%")
.Extensions(e => e.ViewerApi(v => v.OnItemWidgetCreated("function(s, e) { customizeWidgets(s, e); }")))
.Extensions(e => e.ViewerApi(v => v.OnItemWidgetUpdated("function(s, e) { customizeWidgets(s, e); }")))
.Extensions(e => e.ViewerApi(v => v.OnItemWidgetUpdating("function(s, e) { unsubscribeFromEvents(s, e); }")))
)
</div>