Custom Reporting Data Sources
  • 12 Mar 2021
  • 1 Minute to read
  • Dark
    Light

Custom Reporting Data Sources

  • Dark
    Light

Article Summary

Custom data sources can also be created via interfaces/subclassing:

  • Specifying resulting cols
  • Specifying when they apply
  • Generating data

To write your own custom data source, create a class that inherits from and implements AbstractCustomDataSource and that is decorated with AutoRegisterReportElement.

This implementation will involve overriding at least three methods: bool Applies(ReportDefinition definition), ReportFieldData[] ReportFields, and DataTable GetData(DataTable table, IReportFilter[] filters, int? limitCount, int pageIndex). Below is an explanation of each method.

Bool Applies (ReportDefinition definition)

The result of this method determines whether this data source is shown as an available data source in the Report Designer. If this method returns false, the data source will not be shown. If it returns true, the data source will be shown. Usually, you will want a data source to show only when no other data source has yet been selected for the report. However, if your data source joins data from another data source, you may want to let this data source still be selectable even after another data source has been configured on the report. Below is an example implementation of this method which will hide the data source whenever the report is already configured with any data source:

 public override bool Applies(ReportDefinition definition)
{
    return definition.HasDataSourcesOrFilters() == false;
}

Public Override ReportFieldData[] ReportFields

The columns of your data source are defined in this method by returning an array of DecisionsFramework.Design.Report.ReportFieldData

A ReportFieldData is constructed as follows:

ReportFieldData reportFieldData = new ReportFieldData("SampleDataSource", "Time", typeof(DateTime)); 

In this example, SampleDataSource is the table name which is defined in the GetData() method, Time is the name of the column, and typeof(DateTime) is the data type of the data in this column.

Public Override DataTable GetData(DataTable table, IReportFilter[] filters, int? limitCount, int pageIndex)

In this method, you define the actual data which will be returned to the report by building up a DataTable.


Was this article helpful?