Custom Reporting Data Sources (Advanced)
  • 24 Aug 2021
  • 1 Minute to read
  • Dark
    Light
  This documentation version is deprecated, please click here for the latest version.

Custom Reporting Data Sources (Advanced)

  • Dark
    Light

Article summary

Overview

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

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


Example

  1. Create a custom data source.
  2. 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). 


Methods to Override

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. It is best to show a data source only when no other data source has yet been selected for the Report. However, if the data source joins data from another data source, 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 the data source are defined in this method by returning an array of DecisionsFramework.Design.Report.ReportFieldData.

Below is how a ReportFieldData is constructed:

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)

This method is where the actual data is defined that will be returned to the Report by building up a DataTable.


Was this article helpful?