[{"id":"5efffa63-6bf4-4819-8af7-0f6b8e1c53a4","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"dfd416a6-eef9-49a0-bb8b-2e739da5cc1c","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"3b1e4fc6-fe58-48c3-b090-4335186ca05c","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"7f93f7b9-9f7f-46b2-b05f-494017b34eae","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"95079239-11e6-44bd-8e3f-4c5b9f8e172c","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"43ece935-4016-4eb3-a3f8-5951257cb2a7","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"b2fdc309-b91f-42a8-b6f5-5c04d366748e","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"bb982598-dc4e-4495-884c-64f4338def46","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"c632c625-e3a4-4a10-abfa-66bf4a2cd520","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"8fc7bf9e-d24f-43cd-a915-6f8a991152c4","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"7e488fdd-64d8-4c8f-9f96-7a9590f02070","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"4d93a50e-208e-44ef-8ea6-8e81d4c8f339","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"e77dbdc2-200d-4c9c-9bf7-907a453eccb0","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"eecc4b5c-431b-4677-887b-a523a0d10cfd","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"ba126ca3-9e37-4aed-b486-a79bd39b3d86","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"5792319e-7207-4871-a69d-aa3b6eabad63","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"eb1cc175-3766-46e9-9659-c125771a58d4","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"212b23f1-4bfe-46f9-91cf-f24eca55418d","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]}]
Modern front-end frameworks, such as Angular, React, or Vue, are using webpack under the hood to transpile the application's code into instructions consumable in a browser. We recommend including report templates into module dependency graph so that they will go through webpack with the following benefits:
Not Found
errors for your users.Webpack's loaders feature allows us to import
anything directly from JavaScript modules.
ActiveReportsJS uses JSON format and rdlx-json
extension for report template files. Webpack includes the json-loader library that you can use to load JSON files with a custom extension. You can install this package into the Angular, React, or Vue application by running the npm install -D json-loader
or yarn add json-loader -D
command from the application's root folder.
TypeScript becomes a primary language for modern web-application development. Angular, React, and Vue frameworks offer project boilerplates that written in TypeScript. It has a lot of great features, among them WildCard Module Declaration that allows supplying custom modules, like *.rdlx-json
files with strong typing. The structure of ActiveReportsJS templates is defined in the RDLReportDefinition interface that is part of the @grapecity/activereports package. You can add a file called activereports.d.ts
in the root folder of an Angular, React, or Vue application and add the following content into this file:
declare module '*.rdlx-json' {
import { RDLReportDefinition } from '@grapecity/activereports/core';
const report: RDLReportDefinition;
export default report;
}
After that, you can import report templates using the inline loaders.
// eslint-disable-next-line import/no-webpack-loader-syntax
import report from '!json-loader!../reports/Products.rdlx-json';
The name of the report template module consists of the loader name json-loader
, the relative path to the rdlx-json
file, the separator between them, and the prefixing !
.
Alternatively, you can add a custom webpack configuration that specifies the rules for loading *.rdlx-json
modules. However, it requires additional setup that is framework-specific and therefore we don't describe it here.
IDE's such as Visual Studio Code that can recognize Typescript will provide the intellisence for a report template. You can easily modify it at runtime, as shown in the picture below.
You can use the viewer.open method to load an imported report template into a viewer instance. The following examples show the complete code of Angular, React, and Vue TypeScript components using the described approach.
import { Component, ViewChild } from '@angular/core';
import { ViewerComponent } from '@grapecity/activereports-angular';
// eslint-disable-next-line import/no-webpack-loader-syntax
import report from '!json-loader!../reports/Products.rdlx-json';
@Component({
selector: 'app-root',
template: `<div id="viewer-host">
<gc-activereports-viewer (init)="onViewerInit()"></gc-activereports-viewer>
</div>`,
styleUrls: ['./app.component.css'],
})
export class AppComponent {
@ViewChild(ViewerComponent, { static: false }) reportViewer: ViewerComponent;
onViewerInit() {
this.reportViewer.open(report);
}
}
import React from "react";
import { Viewer } from "@grapecity/activereports-react";
// eslint-disable-next-line import/no-webpack-loader-syntax
import report from "!json-loader!../reports/ProductsReport.rdlx-json";
const ViewerApp: React.FC = () => {
const viewerRef = React.useRef<Viewer>(null);
React.useEffect(() => {
const viewerInstance = viewerRef.current?.Viewer;
viewerInstance?.open(report);
}, []);
return (
<div id="viewer-host">
<Viewer ref={viewerRef} />
</div>
);
};
<template>
<div id="viewer-host">
<JSViewer ref="reportViewer"></JSViewer>
</div>
</template>
<script>
import { Viewer } from "@grapecity/activereports-vue";
// eslint-disable-next-line import/no-webpack-loader-syntax
import report from "!json-loader!../reports/ProductsReport.rdlx-json";
export default {
name: "App",
components: {
JSViewer: Viewer
},
mounted() {
const viewer = this.$refs.reportViewer.Viewer();
viewer.open(report);
}
};
</script>
If you don't use TypeScript yet, the syntax for loading reports is slightly different:
import * as report from '!json-loader!../reports/ProductsReport.rdlx-json';
But you can pass the report
variable into the viewer.open method precisely as shown in the preceding section.