Articles in this section
Category / Section

How to import the ReportViewer component in react application

6 mins read

Steps to integrate Syncfusion ReportViewer into Create React App (JavaScript)

 

 

npm install create-react-app -g

 

 

  • Create react application using the below command.

 

create-react-app reports

 

 

npm install create-react-classsave
npm install @syncfusion/reporting-react --save

 

  • Import the required files in App.js.

 

[App.js]

/* eslint-disable */ //Add this command to avoiding the lint error in application
import React from 'react';
import logo from './logo.svg';
import './App.css';
//Report viewer source
import '@syncfusion/reporting-javascript/Scripts/reports/ej.report-viewer.min';
import '@syncfusion/reporting-javascript/Content/reports/material/ej.reports.all.min.css';
//Reports react base
import '@syncfusion/reporting-react/Scripts/reports/ej.reporting.react.min';
 
function App() {
    return (
        <div className="App">
            <EJ.ReportViewer id="reportviewer-container"
                reportServiceUrl={'https://reports.syncfusion.com/demos/services/api/SamplesReportViewer'}
                reportPath={"company-sales"}
                processingMode={"remote"}
            >
            </EJ.ReportViewer>
        </div>
    );
}
 
export default App;

 

  • To render our components, we need jQuery, React, ReactDOM, CreateReactClass instances in browser window. We achieved this, by injecting these values into window object in globals.js file and referred this file in index.js

 

[globals.js]

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;

 

  • Build and run the application using the below command.

 

npm run build

 

  • The application will be launched into default 3000 port.

 

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/js-sample1986940918.zip

 

Steps to integrate Syncfusion ReportViewer into Create React App (TypeScript)

 

 

npm install create-react-app -g

 

 

  • Create react application using the below command.

 

create-react-app reports -- typescript

 

 

npm install create-react-classsave
 
npm install @syncfusion/reporting-react --save
 
npm install @types/create-react-class --save
 
npm install @types/ej.web.all --save
 
npm install @types/jquery --save

 

  • Import the required files and declare EJ in App.tsx.

 

[App.tsx]

//Report viewer source
import ‘@syncfusion/reporting-javascript/Scripts/reports/ej.report-viewer.min’;
import ‘../node_modules/@syncfusion/reporting-javascript/Content/reports/material/ej.reports.all.min.css’;
 
//Reports react base
import '@syncfusion/reporting-react/Scripts/reports/ej.reporting.react.min';
declare let EJ: any;

    

  • To render our components, we need jQuery, React, ReactDOM, CreateReactClass instances in browser window. We achieved this, by injecting these values into window object in globals.ts file and referred this file in index.tsx

 

[globals.ts]

import jquery from 'jquery';
import React from 'react';
import createReactClass from 'create-react-class';
import ReactDOM from 'react-dom';
 
(window as any).React = React;
(window as any).createReactClass = createReactClass;
(window as any).ReactDOM = ReactDOM;
(window as any).$ = (window as any).jQuery = jquery;

 

  • Build and run the application using the below command.

 

npm run build

 

  • The application will be launched into default 3000 port.

 

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ts-sample-1934195325.zip

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (3)
Please  to leave a comment
ID
Isheanesu Doro

I have followed the Javascript Guide but the ReportViewer flickers for a second then I get this error:

'EJ' is not defined react/jsx-no-undef

MS
Mahendran Shanmugam

Hi Isheanesu ,

The mentioned issue occurs when script is not refereed properly in your application. We have prepared the simple sample with Web API service application. Could you please check and confirm the below sample is working or not. React: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ReactApplication1699717346.zip Service: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ReportService--275400096.zip

If issue still persists in your sample then could you please share your issue reproducible sample to validate the mentioned problem at our end.

Regards, Mahendran S.

MS
Mahendran Shanmugam

Hi Isheanesu,

Sorry for the inconvenience caused.

The mentioned issue is a lint error issue and we need to add the lint error disable in App.js file as shown in below eslint-disable code example.


/* eslint-disable */ //Add this command to avoiding the lint error in application
import React from 'react';
import logo from './logo.svg';
import './App.css';
//Report viewer source
import '@syncfusion/reporting-javascript/Scripts/reports/ej.report-viewer.min';
import '@syncfusion/reporting-javascript/Content/reports/material/ej.reports.all.min.css';
//Reports react base
import '@syncfusion/reporting-react/Scripts/reports/ej.reporting.react.min';

function App() {
  return (
    <div className="App">
      <EJ.ReportViewer id="reportviewer-container"
        reportServiceUrl={'https://reports.syncfusion.com/demos/services/api/SamplesReportViewer'}
        reportPath={"company-sales"}
        processingMode={"remote"}
      >
      </EJ.ReportViewer>
    </div>
  );
}

export default App;

Regards, Mahendran S.

SI
sini

Followed the javascript sample, but getting error- Unable to progress the Report action due to failure of connecting Report Service. Could you please help?

AK
Aarti Kanwar

Will these globally scoped values have any effect on the react project user is working on?

Access denied
Access denied