Custom Reporting Data Sources
  • 14 Oct 2022
  • 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, 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?