Skip to main content

IObjectDataSourceCustomFillService Interface

Allows you to implement a custom fill service for the DashboardObjectDataSource.

Namespace: DevExpress.DashboardCommon

Assembly: DevExpress.Dashboard.v24.1.Core.dll

NuGet Package: DevExpress.Dashboard.Core

Declaration

public interface IObjectDataSourceCustomFillService

Remarks

The custom fill service allows you to get access to the DashboardObjectDataSource data (data fields used in a dashboard, the filter expression, parameters and their actual values) and use it in the current data query.

Call the default configurator’s DashboardConfigurator.SetObjectDataSourceCustomFillService(IObjectDataSourceCustomFillService) method to assign this service to the Web Dashboard control.

To provide a custom fill service for the DashboardObjectDataSource, implement the IObjectDataSourceCustomFillService.GetData method where you can obtain object data source’s data before you send it to a dashboard.

Note that the IObjectDataSourceCustomFillService is executed if you use typeof() to specify the ObjectDataSource.DataSource property:

DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source", typeof(SalesPersonData));

Example

This example shows how to bind the ASP.NET MVC Dashboard extension to the Object Data Source and supply it with data using a custom fill service by implementing a IObjectDataSourceCustomFillService interface.

You can use the custom fill service (IObjectDataSourceCustomFillService to get access to the DashboardObjectDataSource data (data fields used in a dashboard, the filter expression, parameters and their actual values) and use it in the current data query.

The IObjectDataSourceCustomFillService is executed if you use typeof() to specify the ObjectDataSource.DataSource property.

In this example, the ObjectDataSourceFillParameters.DataFields parameter is used to load data only for required fields.

View Example

using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using DevExpress.DashboardWeb.Mvc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading;
using System.Web.Routing;

public class DashboardConfig {
    public static void RegisterService(RouteCollection routes) {
        routes.MapDashboardRoute("dashboardControl", "DefaultDashboard");

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

        DashboardConfigurator.Default.SetObjectDataSourceCustomFillService(new CustomObjectDataSourceCustomFillService());
    }
}

public class SalesPersonData {
    public string SalesPerson { get; set; }
    public int Quantity { get; set; }
}

public class CustomObjectDataSourceCustomFillService : IObjectDataSourceCustomFillService {
    public object GetData(DashboardObjectDataSource dataSource, ObjectDataSourceFillParameters fillParameters) {
        if (fillParameters.DataFields == null || fillParameters.DataFields.Length == 0) {
            return null;
        }

        List<SalesPersonData> data = DataGenerator.CreateSourceData();

        DataTable table = new DataTable();
        foreach(string field in fillParameters.DataFields) {
            table.Columns.Add(field, typeof(SalesPersonData).GetProperty(field).PropertyType);
        }
        for (int i = 0; i < data.Count; i++) {
            object[] row = new object[fillParameters.DataFields.Length];
            for (int j = 0; j < fillParameters.DataFields.Length; j++) {
                row[j] = GetPropertyValue(data[i], fillParameters.DataFields[j]);
            }
            table.Rows.Add(row);
        }
        return table.DefaultView;
    }
    object GetPropertyValue(SalesPersonData obj, string propName) {
        return propName == "SalesPerson" ? (object)obj.SalesPerson : (object)obj.Quantity;
    }
}

public static class DataGenerator {
    public static List<SalesPersonData> CreateSourceData() {
        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;
    }
}
See Also