Back to Devexpress

DashboardConfigurator.DataLoading Event

dashboard-devexpress-dot-dashboardweb-dot-dashboardconfigurator-ff9b3f66.md

latest15.3 KB
Original Source

DashboardConfigurator.DataLoading Event

Allows you to provide data for the DashboardObjectDataSource.

Namespace : DevExpress.DashboardWeb

Assembly : DevExpress.Dashboard.v25.2.Web.dll

NuGet Package : DevExpress.Web.Dashboard.Common

Declaration

csharp
public event DataLoadingWebEventHandler DataLoading
vb
Public Event DataLoading As DataLoadingWebEventHandler

Event Data

The DataLoading event's data class is DataLoadingWebEventArgs. The following properties provide information specific to this event:

PropertyDescription
DashboardIdGets the identifier of the current dashboard.
DataGets or sets data for the current data source. Inherited from DataLoadingEventArgs.
DataIdGets an object data source’s unique identifier. Inherited from DataLoadingEventArgs.
DataSourceComponentNameGet the component name of the data source for which the event has been raised. Inherited from DataLoadingEventArgs.
DataSourceNameGets the name of the data source for which the event has been raised. Inherited from DataLoadingEventArgs.
OverwriteDataSourcePropertySpecifies whether the DataSource and DataMember properties of the DashboardObjectDataSource are set when data is supplied in the event handler. Inherited from DataLoadingEventArgs.
ParametersProvides access to parameter values passed to the object data source. Inherited from DataLoadingEventArgs.

Remarks

Tip

For information on how to use the DashboardConfigurator‘s API, see the following topic: Server-Side API Overview.

The DataLoading event is raised when the dashboard needs to load data from a data source assigned using the DashboardObjectDataSource. Use the event parameter’s DataLoadingEventArgs.Data property to provide data for this data source. This object should implement the IEnumerable or IListSource interface.

For other data source types (for instance, DashboardSqlDataSource or DashboardOlapDataSource), you can handle the DashboardConfigurator.ConfigureDataConnection event to customize connection parameters.

Example

This example shows how to bind the ASP.NET MVC Dashboard extension to the Object Data Source and supply it with data using the DashboardConfigurator.DataLoading event. To use the created data source, run the application and create a new dashboard.

cshtml
@{
    ViewBag.Title = "Index";
}

<div style="position: absolute; left: 0; right: 0; top:0; bottom:0;">
    @Html.DevExpress().Dashboard(settings => {
    settings.Name = "Dashboard";
    settings.Width = Unit.Percentage(100);
    settings.Height = Unit.Percentage(100);
}).GetHtml()
</div>
cshtml
<!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8" />
    <title>@ViewBag.Title</title>

    @Html.DevExpress().GetStyleSheets( 
        new StyleSheet { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
        new StyleSheet { ExtensionSuite = ExtensionSuite.Editors },
        new StyleSheet { ExtensionSuite = ExtensionSuite.GridView },
        new StyleSheet { ExtensionSuite = ExtensionSuite.Dashboard }
    )
    @Html.DevExpress().GetScripts( 
        new Script { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
        new Script { ExtensionSuite = ExtensionSuite.Editors },
        new Script { ExtensionSuite = ExtensionSuite.GridView },
        new Script { ExtensionSuite = ExtensionSuite.Dashboard }
    )

</head>

<body>
    @RenderBody()
</body>
</html>
csharp
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using DevExpress.DashboardWeb.Mvc;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Web.Routing;

public class DashboardConfig {
    public static void RegisterService(RouteCollection routes) {
        routes.MapDashboardRoute();

        DashboardConfigurator.Default.SetDashboardStorage(new DashboardFileStorage(@"~/App_Data/"));

        var dataSourceStorage = new DataSourceInMemoryStorage();
        DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage);
        DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source");
        objDataSource.DataSource = typeof(SalesPersonData);
        dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml());

        DashboardConfigurator.Default.DataLoading += Default_DataLoading;
    }

    private static void Default_DataLoading(object sender, DataLoadingWebEventArgs e) {
        if (e.DataSourceName == "Object Data Source") {
            e.Data = CreateData();
        }
    }

    public static List<SalesPersonData> CreateData() {
        List<SalesPersonData> data = new List<SalesPersonData>();
        string[] salesPersons = { "Andrew Fuller", "Michael Suyama",
                                    "Robert King", "Nancy Davolio",
                                    "Margaret Peacock", "Laura Callahan",
                                    "Steven Buchanan", "Janet Leverling" };

        for (int i = 0; i < 100; i++) {
            SalesPersonData record = new SalesPersonData();
            int seed = (int)DateTime.Now.Ticks & 0x0000FFFF;
            record.SalesPerson = salesPersons[new Random(seed).Next(0, salesPersons.Length)];
            record.Quantity = new Random(seed).Next(0, 100);
            data.Add(record);
            Thread.Sleep(3);
        }
        return data;
    }
}

public class SalesPersonData {
    public string SalesPerson { get; set; }
    public int Quantity { get; set; }
}
vb
Imports System.Threading
Imports System.Web.Routing
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWeb
Imports DevExpress.DashboardWeb.Mvc

Public Class DashboardConfig
    Public Shared Sub RegisterService(ByVal routes As RouteCollection)
        routes.MapDashboardRoute()

        DashboardConfigurator.Default.SetDashboardStorage(New DashboardFileStorage("~/App_Data/"))

        Dim dataSourceStorage = New DataSourceInMemoryStorage()
        DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage)
        Dim objDataSource As New DashboardObjectDataSource("Object Data Source")
        objDataSource.DataSource = GetType(SalesPersonData)
        dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml())

        AddHandler DashboardConfigurator.Default.DataLoading, AddressOf Default_DataLoading
    End Sub

    Private Shared Sub Default_DataLoading(ByVal sender As Object, ByVal e As DataLoadingWebEventArgs)
        If e.DataSourceName = "Object Data Source" Then
            e.Data = CreateData()
        End If
    End Sub

    Public Shared Function CreateData() As List(Of SalesPersonData)
        Dim data As New List(Of SalesPersonData)()
        Dim salesPersons() As String = {"Andrew Fuller", "Michael Suyama",
                                            "Robert King", "Nancy Davolio",
                                            "Margaret Peacock", "Laura Callahan",
                                            "Steven Buchanan", "Janet Leverling"}

        For i As Integer = 0 To 99
            Dim record As New SalesPersonData()
            Dim seed As Long = CLng(Date.Now.Ticks) And &HFFFF
            record.SalesPerson = salesPersons((New Random(seed)).Next(0, salesPersons.Length))
            record.Quantity = (New Random(seed)).Next(0, 100)
            data.Add(record)
            Thread.Sleep(3)
        Next i
        Return data
    End Function
End Class

Public Class SalesPersonData
    Public Property SalesPerson() As String
    Public Property Quantity() As Integer
End Class
cshtml
@{
    ViewBag.Title = "Index";
}

<div style="position: absolute; left: 0; right: 0; top:0; bottom:0;">
    @Html.DevExpress().Dashboard(settings => {
    settings.Name = "Dashboard";
    settings.Width = Unit.Percentage(100);
    settings.Height = Unit.Percentage(100);
}).GetHtml()
</div>
cshtml
<!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8" />
    <title>@ViewBag.Title</title>

    @Html.DevExpress().GetStyleSheets( 
        new StyleSheet { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
        new StyleSheet { ExtensionSuite = ExtensionSuite.Editors },
        new StyleSheet { ExtensionSuite = ExtensionSuite.GridView },
        new StyleSheet { ExtensionSuite = ExtensionSuite.Dashboard }
    )
    @Html.DevExpress().GetScripts( 
        new Script { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
        new Script { ExtensionSuite = ExtensionSuite.Editors },
        new Script { ExtensionSuite = ExtensionSuite.GridView },
        new Script { ExtensionSuite = ExtensionSuite.Dashboard }
    )

</head>

<body>
    @RenderBody()
</body>
</html>

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataLoading event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

asp-net-core-dashboard-custom-item-gallery/CS/AspNetCoreCustomItem/Startup.cs#L62

csharp
configurator.DataLoading += Configurator_DataLoading;
configurator.ConfigureDataConnection += Configurator_ConfigureDataConnection; ;

dashboard-blazor-webassembly-localization/CS/BlazorDashboardApp/BlazorDashboardApp.Server/Code/DashboardUtils.cs#L17

csharp
DashboardObjectDataSource objectDataSource = new DashboardObjectDataSource("Object Data Source") { DataId = "employees" };
configurator.DataLoading += (s, e) => {
    if (e.DataId == "employees") {

dashboard-blazor-server-localization/CS/BlazorDashboardApp/Code/DashboardUtils.cs#L16

csharp
DashboardObjectDataSource objectDataSource = new DashboardObjectDataSource("Object Data Source") { DataId = "employees" };
configurator.DataLoading += (s, e) => {
    if (e.DataId == "employees") {

asp-net-core-dashboard-export-all-items/CS/AspNetCoreDashboard_ExportAllItems/Startup.cs#L65

csharp
configurator.DataLoading += (s, e) => {
    if(e.DataSourceName == "Object Data Source") {

asp-net-core-dashboard-custom-interactivity/CS/AspNetCoreDashboard_CustomInteractivity/Code/DashboardUtils.cs#L42

csharp
configurator.DataLoading += (s, e) => {
    if(e.DataId == "Object Data Source Data Id") {

aspnet-mvc-dashboard-data-federation/VB/MVC_DataFederationExample/App_Start/DashboardConfig.vb#L56

vb
DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage)
AddHandler DashboardConfigurator.Default.DataLoading, AddressOf DataLoading
AddHandler DashboardConfigurator.Default.ConfigureDataConnection, AddressOf Default_ConfigureDataConnection

asp-net-mvc-dashboard-register-data-sources/VB/MvcDashboardDataSources/Configuration/ObjectDataSourceConfigurator.vb#L12

vb
AddHandler configurator.DataLoading, AddressOf DataLoading

See Also

ConfigureDataConnection

DashboardConfigurator Class

DashboardConfigurator Members

DevExpress.DashboardWeb Namespace