Add Web Report Viewer Classic to a React application
To add the Bold Reports® React Report Viewer Classic to a React application, create a React application, install the @boldreports/react-reporting-components package, import the Report Viewer scripts and styles, and set a Web API service URL.
To get started quickly with the React Report Viewer Classic, watch the following video:
What do I need before adding the classic Report Viewer to a React app?
To add the Bold Reports® Report Viewer Classic to a React app, your development environment needs Node JS (version 8.x or 10.x) and NPM (v3.x.x or higher).
Before you begin with the Bold Reports® React Report Viewer Classic, make sure your development environment includes the following:
Install the Create React App package
To install Create React App globally on your machine, run the following command in the Command Prompt. Create React App is a simple way to create a single-page React application with a build setup that needs no configuration.
npm install create-react-app -gTo learn more about the Create React App package, refer to the Create React App documentation on GitHub.
Create a new React application
To create a new React application, run the following command in the Command Prompt.
create-react-app reportsThe
create-react-appcommand adds thereact,react-dom,react-scripts, and other dependencies required for your React application.
The source code for this React reporting components application is available on GitHub.
Install the Create React Class
To configure the Report Viewer component, change the directory to your application’s root folder.
cd reportsTo install the type definitions for create-react-class, run the following command in the Command Prompt.
npm install create-react-class --saveInstall 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 --saveAdding scripts reference
Bold Reports® needs a window.jQuery object to render the React components. Create a file named globals.js in the src folder and import jQuery into the globals.js file, as 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;Refer to the globals.js file in the index.js file, as in the following code snippet:
import './globals';
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));import './globals';
import React from 'react';
import {{ createRoot }} from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);How do I add the Report Viewer component to a React app?
You add the Bold Reports® Report Viewer Classic component to a React app by importing the Report Viewer script and style files into the App.js file.
To run the Bold Reports® React Report Viewer Classic, import the Report Viewer script and style 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': '700px', 'width': '100%'};
function App() {
return (
<div style={viewerStyle}>
<BoldReportViewerComponent
id="reportviewer-container">
</BoldReportViewerComponent>
</div>
);
}
export default App;Open the public\index.html and refer the following scripts in the <head> tag.
<!-- Data-Visualization -->
<script src="https://cdn.boldreports.com/15.1.10/scripts/common/ej2-base.min.js"></script>
<script src="https://cdn.boldreports.com/15.1.10/scripts/common/ej2-data.min.js"></script>
<script src="https://cdn.boldreports.com/15.1.10/scripts/common/ej2-pdf-export.min.js"></script>
<script src="https://cdn.boldreports.com/15.1.10/scripts/common/ej2-svg-base.min.js"></script>
<script src="https://cdn.boldreports.com/15.1.10/scripts/data-visualization/ej2-lineargauge.min.js"></script>
<script src="https://cdn.boldreports.com/15.1.10/scripts/data-visualization/ej2-circulargauge.min.js"></script>
<script src="https://cdn.boldreports.com/15.1.10/scripts/data-visualization/ej2-maps.min.js"></script>Set a Web API service URL
To set a Web API service for the React Report Viewer Classic, open the App.js file and replace the existing code with the following code snippet:
/* 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': '700px', '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;