Search results

Display ssrs rdl report in Syncfusion Angular Report Viewer

This section explains you the steps required to create your first Angular reporting application in Angular CLI to display already created SSRS RDL report in Syncfusion Angular Report Viewer without using a Report Server, refer to the following steps:

Prerequisites

Before you begin, make sure your development environment includes the following,

  • Node JS (version 8.x or 10.x)
  • NPM (v3.x.x or higher)

Install the Angular CLI

Angular provides the easiest way to set Angular CLI projects using the Angular CLI tool. To install the CLI application globally to your machine, run the following command in the Command Prompt.

npm install -g @angular/cli

To learn more about angular-cli commands, refer to here.

Create a new application

To create a new Angular application, run the following command in the Command Prompt.

ng new project-name

E.g : ng new reportviewerapp

The ng new command prompts you for information about features to include in the initial app project. Accept the defaults by pressing the Enter or Return key.

Accept the initial app project defaults by pressing the Enter or Return key

Configure Syncfusion Report Viewer in Angular CLI

Syncfusion Reporting packages are distributed in npm as @syncfusion/reporting-angular.

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

    cd project-name
    
    E.g : cd reportviewerapp
  2. Run the following commands to install the dependencies.

    npm install @syncfusion/reporting-angular --save
  3. Install the typings dependencies jquery and ej.web.all.

    npm install --save-dev @types/jquery
    npm install --save-dev @types/ej.web.all
  4. Add the typings jquery, and ej.web.all to the src/tsconfig.app.json file.

    {
      ...
      ...
      "compilerOptions": {
        ...
        ...
        "baseUrl": "",
        "types": [
          "jquery",
          "ej.web.all"
        ]
      },
      ...
      ...
    }
  5. Report Viewer requires window.jQuery object to render the component. Import jQuery in the src/polyfills.ts file as shown in the following code snippet.

    import * as jquery from 'jquery';
    window['jQuery'] = jquery;
    window['$'] = jquery;

    Refer to the already configured import codes in the webpack angular seed application.

Adding CSS reference

Add Report Viewer component style (ej.reports.all.min.css) as given in the angular.json file within the pojectname -> styles section (Eg. reportviewerapp -> styles).

If you are using Angular 6 or lower version project, add the changes in the angular-cli.json file.

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "reportviewerapp"
  },
  "reportviewerapp": [
    {
      "root": "src",
      "outDir": "dist",
       . . .
       . . .
      "styles": [
        "styles.css",
         "./node_modules/@syncfusion/reporting-javascript/Content/reports/material/ej.reports.all.min.css"
      ],
      "scripts": [],
       . . .
       . . .
      }

In the previous code, the material theme is used. You can modify the theme based on your application, refer the following syntax: ./node_modules/@syncfusion/reporting-javascript/Content/reports/[theme-name]/ej.reports.all.min.css

Adding Report Viewer component

To add the Report Viewer component, refer to the following steps:

  1. Open the app.module.ts file.

  2. You can replace the following code snippet in the app.module.ts file.

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { EJ_REPORTVIEWER_COMPONENTS } from '@syncfusion/reporting-angular/src/ej/reportviewer.component';
    import { AppComponent } from './app.component';
    
    @NgModule({
      declarations: [
        AppComponent,
        EJ_REPORTVIEWER_COMPONENTS
      ],
    imports: [
        BrowserModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
  3. Open the app.component.html file and initialize the Report Viewer.

  4. You can replace the following code snippet in the app.component.html file.

    <ej-reportviewer id="reportViewer_Control" style="width: 100%;height: 950px">
    </ej-reportviewer>
  5. Open the app.component.ts and replace the following code example.

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'reportviewerapp';
      public serviceUrl: string;
      public reportPath: string;
    
        constructor() {
            // Initialize the Report Viewer properties here.
        }
    }

    If you have faced the issue 'ej' is not defined after the above configuration in Angular CLI latest version 7, refer to the following code snippet in your application where you have rendered Syncfusion Components(model file) to resolve the issue.

    `/// <reference types="ej.web.all" />`

Create Web API service

The Report Viewer requires a Web API service to process the report files. You can skip this step and use the online Web API services to preview the already available reports or you should create any one of the following Web API services:

Adding already created report

If you have created a new service, you can add the reports from the Syncfusion installation location. For more information, refer to samples and demos section.

  1. Create a folder Resources in your Web API application to store the RDL reports and add already created reports to it.

  2. Add already created reports to the newly created folder.

    In this tutorial, the sales-order-detail.rdl report is used, and it can be downloaded in this link.

Refer to the create RDL report section for creating new reports.

Set report path and Web API service

To set report path and Web API service, open the app.component.ts file and add the codes as shown in the constructor.

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'jsreport-sample';
  public serviceUrl: string;
  public reportPath: string;

    constructor() {
        this.serviceUrl = 'https://reports.syncfusion.com/demos/services/api/ReportViewer';
        this.reportPath = '~/Resources/docs/sales-order-detail.rdl';
    }
}

In the above code, the sales-order-detail.rdl report and reportServiceUrl used from online URL.

Open the app.component.html to set reportPath and reportServiceUrl properties of Report Viewer as in the following.

<ej-reportviewer id="reportViewer_Control" [reportServiceUrl] = "serviceUrl" [reportPath] = "reportPath" style="width: 100%;height: 950px">
</ej-reportviewer>

Serve the application

To serve the application, follow these steps:

  1. Navigate to the root of the application and run the application using the following command.

    ng serve
  2. Navigate to the appropriate port http://localhost:4200 in the browser.

  3. Click view option to view the demo.

app.component.ts
app.component.html
app.module.ts
import { Component } from '@angular/core';

@Component({
  selector: 'ej-sample',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  public serviceUrl: string;  
  public reportPath: string;

    constructor() {
        this.serviceUrl = 'https://reports.syncfusion.com/demos/services/api/ReportViewer';
        this.reportPath = '~/Resources/docs/sales-order-detail.rdl';
    }
}
<ej-reportviewer id="report-viewer" [reportServiceUrl]="serviceUrl" [reportPath]="reportPath">
</ej-reportviewer>
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { EJ_REPORTVIEWER_COMPONENTS } from '@syncfusion/reporting-angular/src/ej/reportviewer.component';
import { EJ_REPORTDESIGNER_COMPONENTS } from '@syncfusion/reporting-angular/src/ej/reportdesigner.component';
import { AppComponent } from './app.component';

// data-visualization
import '@syncfusion/reporting-javascript/Scripts/reports/data-visualization/ej.bulletgraph.min';
import '@syncfusion/reporting-javascript/Scripts/reports/data-visualization/ej.chart.min';
import '@syncfusion/reporting-javascript/Scripts/reports/data-visualization/ej.circulargauge.min';
import '@syncfusion/reporting-javascript/Scripts/reports/data-visualization/ej.lineargauge.min';
import '@syncfusion/reporting-javascript/Scripts/reports/data-visualization/ej.map.min';

// code-mirror
import 'codemirror/lib/codemirror';
import 'codemirror/addon/hint/show-hint';
import 'codemirror/addon/hint/sql-hint';
import 'codemirror/mode/sql/sql';
import 'codemirror/mode/vb/vb';

import * as CodeMirror from 'codemirror';
const codemirror = 'CodeMirror';
window[codemirror] = CodeMirror;

@NgModule({
  declarations: [
    AppComponent,
    EJ_REPORTDESIGNER_COMPONENTS,
    EJ_REPORTVIEWER_COMPONENTS
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

See Also

Render Report Server reports

Create RDLC report

Render RDLC reports

Preview report in print mode

Set data source credential for shared data sources

Change data source connection string

Production deployment