Add the Report Viewer to a React Application | React Reporting Tools | Bold Reports

Add the Report Viewer to a React Application

Umamageswari Elumalai
Bold Reports

--

In this blog, I will walk you through the integration of Bold Report’s Report Viewer for React component into an app.

The Report Viewer is a visualization control used to display SSRS RDL and RDLC reports within web applications. It allows you to view RDL/RDLC reports with or without using SSRS. This component comes with a wide range of report items to transform your business data into meaningful information.

Prerequisites

Install Create React App

Create React App is a simple and effective way to create a single-page React application that provides a build setup with no configuration. To install the Create React App globally on your machine, run the following command in the command prompt.

npm install create-react-app -g

Note: To learn more about the Create React App package, refer to this page.

Create a new React application

To create a new React application, run the following command in the command prompt.

create-react-app reportviewer

The create-react-app command adds the react, react-dom, react-scripts, and other dependencies required for your React application.

Create a New React Application
Create a New React Application

Install the Create React Class package

To configure the Report Viewer component, change the directory to your application’s root folder.

cd reportviewer

To install the type definitions for create-react-class, run the following command in the command prompt.

npm install create-react-class –save--dev
Create React Class Package
Create React Class Package

Install the Bold Reports React Package

To install the Bold Reports React package, run the following command in the command prompt.

npm install @boldreports/react-reporting-components –save--dev
Install the Bold Reports React Package
Install the Bold Reports React Package

Add Scripts Reference

Bold Reports needs a window.jQuery object to render the React components. So, create a file named globals.js in the src folder and import jQuery into the globals.js file, like in the following code snippet.

import jquery from 'jquery';
import React from 'react';
import createReactClass from 'create-react-class';
import ReactDOM from 'react-dom';

window.React = React;
window.createReactClass = createReactClass;
window.ReactDOM = ReactDOM;
window.$ = window.jQuery = jquery;
Render React Components
Render React Components

Reference the globals.js file in the index.js file, like in the following code snippet.

import './globals'
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
Import globals
Import globals

Add React Report Viewer Component

Now, let’s add the Report Viewer component. The Bold Report Viewer script and style files need to be imported in order to run the web Report Viewer. Import the following files into the App.js file.

/* eslint-disable */
import React from 'react';
import './App.css';
//Report Viewer source
import '@boldreports/javascript-reporting-controls/Scripts/bold.report-viewer.min';
import '@boldreports/javascript-reporting-controls/Content/material/bold.reports.all.min.css';
//Data-Visualization
import '@boldreports/javascript-reporting-controls/Scripts/data-visualization/ej.bulletgraph.min';
import '@boldreports/javascript-reporting-controls/Scripts/data-visualization/ej.chart.min';
//Reports react base
import '@boldreports/react-reporting-components/Scripts/bold.reports.react.min';

var viewerStyle = {'height': '900px', 'width': '100%'};

function App() {
return (
<div style={viewerStyle}>
<BoldReportViewerComponent
id="reportviewer-container">
</BoldReportViewerComponent>
</div>
);
}

export default App;
Import viewerStyle Object
Import viewerStyle Object

The highlighted viewerStyle is an object used to store the width and height of the Report Viewer control.

Import App Function
Import App Function

The highlighted App function will return the Report Viewer component.

Open public > index.html and reference the following scripts in the <head> tag.

<title>Bold Reports – Report Viewer</title>
<!-- Data-Visualization -->
<script src="https://cdn.boldreports.com/4.2.52/scripts/common/ej2-base.min.js"></script>
<script src="https://cdn.boldreports.com/4.2.52/scripts/common/ej2-data.min.js"></script>
<script src="https://cdn.boldreports.com/4.2.52/scripts/common/ej2-pdf-export.min.js"></script>
<script src="https://cdn.boldreports.com/4.2.52/scripts/common/ej2-svg-base.min.js"></script>
<script src="https://cdn.boldreports.com/4.2.52/scripts/data-visualization/ej2-lineargauge.min.js"></script>
<script src="https://cdn.boldreports.com/4.2.52/scripts/data-visualization/ej2-circulargauge.min.js"></script>
<script src="https://cdn.boldreports.com/4.2.52/scripts/data-visualization/ej2-maps.min.js"></script>
Added Scripts and References
Added Scripts and References

Let’s look at the scripts and style sheets required to render the Report Viewer.

Scripts and Style sheets for React Reporting Tool
Scripts and Style sheets

Set Report Path and Web API Services

The Bold Report Viewer must have a Web API service to process and evaluate the provided SSRS RDL report.

In this blog, I am using the Web API service and the report that is already hosted in an Azure web app.

Note: You can create your own Web API service by referring to our online documentation link.

To render the report, open the App.js file and set the properties of the Report Viewer:

  • The reportPath property is used to specify the path of an RDL report.
  • The reportServiceUrl property is used to specify the Web API service URL required for processing an RDL report.

Note: The Web API service used in the following code is already hosted in the Azure web app.

/* eslint-disable */
import React from 'react';
import './App.css';
//Report Viewer source
import '@boldreports/javascript-reporting-controls/Scripts/bold.report-viewer.min';
import '@boldreports/javascript-reporting-controls/Content/material/bold.reports.all.min.css';
//Data-Visualization
import '@boldreports/javascript-reporting-controls/Scripts/data-visualization/ej.bulletgraph.min';
import '@boldreports/javascript-reporting-controls/Scripts/data-visualization/ej.chart.min';
//Reports react base
import '@boldreports/react-reporting-components/Scripts/bold.reports.react.min';

var viewerStyle = {'height': '900px', 'width': '100%'};

function App() {
return (
<div style={viewerStyle}>
<BoldReportViewerComponent
id="reportviewer-container"
reportServiceUrl = {'https://demos.boldreports.com/services/api/ReportViewer'}
reportPath = {'~/Resources/docs/sales-order-detail.rdl'} >
</BoldReportViewerComponent>
</div>
);
}
export default App;
Set Report Path and Web API Services
Set Report Path and Web API Services

Note: The sales-order-detail.rdl report is from the demo server location and the file is located in the resources/docs/ path.

Run the Application

To run the application, run the following command in the command prompt.

npm run start

It will launch the application in the default browser at the following URL: “ http://localhost:3000/". The npm run start command automatically opens your browser.

Preview Image for Report Viewer Component in a React Application | Reporting Tools
Preview Image for Report Viewer Component in a React Application

As you can see, in the Bold Report Viewer, the sales-order-detail report is loaded.

Conclusion

In this blog, we learned how to integrate the Report Viewer component into a React application. To explore further, go through our sample reports and Bold Reports documentation.

If you have any questions, please post them in the comments section. You can also contact us through our contact page, or if you already have an account, you can log in to submit your support question.

Bold Reports now comes with a 15-day free trial with no credit card information required. We welcome you to start a free trial and experience Bold Reports. Give it a try and let us know what you think!

Stay tuned to our official Twitter, Facebook, LinkedIn, Pinterest, and Instagram pages for announcements about upcoming releases.

Originally published at https://www.boldreports.com on November 30, 2022.

--

--