Runtime Data Binding

These samples show how to supply the data for a report at runtime with Angular, React, Vue, and pure JavaScript applications. For more details, please visit the Data Binding page. To view the code, scroll down the page.

import { Component, ViewChild } from "@angular/core"; import { ViewerComponent, AR_EXPORTS, PdfExportService, HtmlExportService, TabularDataExportService, } from "@grapecity/activereports-angular"; @Component({ selector: "app-root", template: '<div id="viewer-host"><gc-activereports-viewer (init)="onViewerInit()"> </gc-activereports-viewer></div> ', styleUrls: ["src/app.component.css"], providers: [ { provide: AR_EXPORTS, useClass: PdfExportService, multi: true, }, { provide: AR_EXPORTS, useClass: HtmlExportService, multi: true, }, { provide: AR_EXPORTS, useClass: TabularDataExportService, multi: true, }, ], }) export class AppComponent { @ViewChild(ViewerComponent, { static: false }) reportViewer: ViewerComponent; async loadData() { // Use the Fetch Api to pull the data https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch const headers = new Headers(); const dataRequest = new Request( "https://demodata.mescius.io/northwind/api/v1/Customers", { headers: headers, } ); const response = await fetch(dataRequest); const data = await response.json(); return data; } async loadReport() { // load report definition from the file const reportResponse = await fetch( "/activereportsjs/demos/resource/reports/CustomersTable.rdlx-json" ); const report = await reportResponse.json(); return report; } async onViewerInit() { const data = await this.loadData(); const report = await this.loadReport(); // update the embedded data report.DataSources[0].ConnectionProperties.ConnectString = "jsondata=" + JSON.stringify(data); this.reportViewer.open(report); } }
#viewer-host { width: 100%; height: 600px; }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { ActiveReportsModule } from '@grapecity/activereports-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, ActiveReportsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
(function (global) { System.config({ transpiler: './plugin-typescript.js', typescriptOptions: { "target": "es5", "module": "system", }, baseURL: './node_modules/', meta: { 'typescript': { "exports": "ts" }, '*.css': { loader: 'systemjs-plugin-css' } }, packageConfigPaths: [ './node_modules/*/package.json', "./node_modules/@angular/*/package.json", "./node_modules/@grapecity/*/package.json"], map: { 'typescript': 'typescript/lib/typescript.js', "rxjs": "rxjs/dist/bundles/rxjs.umd.js", "rxjs/operators": "rxjs/dist/bundles/rxjs.umd.js", "@grapecity/activereports/core": "@grapecity/activereports/dist/ar-js-core.js", "@grapecity/activereports": "./activereports.js", "@grapecity/ar-js-pagereport": "@grapecity/activereports/dist/ar-js-core.js", }, // packages tells the System loader how to load when no filename and/or no extension packages: { "./src": { defaultExtension: 'ts' }, rxjs: { defaultExtension: 'js', // "main": "bundles/rxjs.umd.min.js" }, "node_modules": { defaultExtension: 'js' }, "@angular/core": { defaultExtension: 'mjs', "main": "fesm2015/core.mjs" }, "@angular/platform-browser": { defaultExtension: 'mjs', "main": "fesm2015/platform-browser.mjs" }, "@angular/common": { defaultExtension: 'mjs', "main": "fesm2015/common.mjs" }, "@angular/compiler": { defaultExtension: 'mjs', "main": "fesm2015/compiler.mjs" }, "@angular/forms": { defaultExtension: 'mjs', "main": "fesm2015/forms.mjs" }, "@angular/localize": { defaultExtension: 'mjs', "main": "fesm2015/localize.mjs" }, "@angular/platform-browser-dynamic": { defaultExtension: 'mjs', "main": "fesm2015/platform-browser-dynamic.mjs" }, "@grapecity/activereports-angular": { defaultExtension: 'mjs', "main": "fesm2015/grapecity-activereports-angular.mjs" } } }); })(this);
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>MESCIUS ActiveReports for Javascript sample</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap" rel="stylesheet" /> <link rel="stylesheet" type="text/css" href="/activereportsjs/demos/resource/themes/orange-ui.css" /> <link rel="stylesheet" type="text/css" href="/activereportsjs/demos/resource/themes/orange-viewer.css" /> <script> System.import("$DEMOROOT$/en/lib/angular/license.ts"); System.import("./src/app.main"); </script> </head> <body> <app-root></app-root> </body> </html>