Connecting Data
Data to a report can be connected in various ways. The easiest way is to store connection settings in the report template. You can also connect the data from the code, this can be done when the report is loaded in the GetReport action.
HomeController.cs |
... public IActionResult GetReport() { DataSet ds = new DataSet(); ds.ReadXml(StiAngularHelper.MapPath(this, "Data/Demo.xml"));
StiReport report = new StiReport(); report.Load(StiAngularHelper.MapPath(this, "Reports/TwoSimpleLists.mrt")); report.Dictionary.Databases.Clear(); report.RegData("Demo", ds);
return StiAngularViewer.GetReportResult(this, report); } ... |
Data for the report can be connected not only when the report is loaded. For example, you can connect new data at the moment of interactive actions in the viewer (applying report parameters, sorting, drill-down, collapsing). To do this, you should set the Interaction action for the Angular Viewer component, and, in the action handler, connect the data for the current report. The same way you can connect data in other actions of the viewer.
HomeController.cs |
... public IActionResult InitViewer() { var requestParams = StiAngularViewer.GetRequestParams(this); var options = new StiAngularViewerOptions(); options.Actions.ViewerEvent = "ViewerEvent"; options.Actions.Interaction = "ViewerInteraction";
return StiAngularViewer.ViewerDataResult(requestParams, options); } ... |
HomeController.cs |
... public IActionResult ViewerInteraction() { DataSet data = new DataSet(); data.ReadXml(StiAngularHelper.MapPath(this, "Data/Demo.xml"));
StiReport report = StiAngularViewer.GetReportObject(this); report.RegData("Demo", data);
return StiAngularViewer.InteractionResult(this, report); } ... |
If you want to connect new data only for a certain interactive action of the viewer, for example, only when you apply report parameters, you can use the parameters of the viewer. The viewer parameters are represented as an object of the StiRequestParams class, they are passed to any server side on any request, and contain all necessary information and states of the client part of the viewer. To determine the type of the action of the viewer, it is enough to check the Action property of the viewer parameters.
HomeController.cs |
... public IActionResult ViewerInteraction() { StiRequestParams requestParams = StiAngularViewer.GetRequestParams(this); if (requestParams.Action == StiAction.Variables) { DataSet data = new DataSet(); data.ReadXml(StiAngularHelper.MapPath(this, "Data/Demo.xml"));
StiReport report = StiAngularViewer.GetReportObject(this); report.RegData("Demo", data);
return StiAngularViewer.InteractionResult(this, report); }
return StiAngularViewer.InteractionResult(this); } ... |
SQL data sources
The connection parameters to the SQL data source, as well as to any other ones, can be stored in the report template. If you want to set the connection parameters from the code before rendering the report (for example, for security reasons or depending on the authorized user), you can use the example below.
Also, for SQL data sources used in the report, you can specify the Query Timeout in seconds. The value of this property is stored in the report template for each SQL connection separately.
Below is an example of code that you may use to change the connection string for MS SQL, adjust the query, set the query timeout for the already created connection, and data sources in the report.
The table below shows the connection string templates for different types of data sources.
|
Data from XML, JSON, Excel files
Connecting to XML and JSON data sources can be stored in the report template. If you want to specify data files from the code, you can use the example below.
|