Report Designer Integration (npm or Yarn Package Managers)
- 6 minutes to read
You can use the End-User Web Report Designer in a JavaScript application. You should create two projects:
- A server (backend) project that enables Cross-Origin Resource Sharing and retrieves a report from the storage
- A client (frontend) part that includes all the necessary styles, scripts, and HTML-templates.
#Server (Backend) Part
#Use the DevExpress CLI Template
You can use DevExpress CLI Templates to create an ASP.NET Core back-end application. Begin with the steps below:
Install DevExpress ASP.NET Core project templates from nuget.org:
dotnet new install DevExpress.AspNetCore.ProjectTemplates
Create a back-end Reporting application:
consoledotnet new dx.aspnetcore.reporting.backend -n ServerApp
You can use the following parameters to see available command options:
-? | -h | --help
.Enable cross-origin requests (CORS). Specify the policy that allows any local application to access the report’s back-end. Use the SetIsOriginAllowed method to set it up.
Call the UseCors method and pass the policy name as a parameter. The
UseCors
method should be called after theUseRouting
method and before any MVC-related code. Place theUseCors
method before theUseMvc
orUseEndpoints
methods.Open the application startup file and insert the following code:
var builder = WebApplication.CreateBuilder(args); builder.Services.AddCors(options => { options.AddPolicy("AllowCorsPolicy", builder => { // Allow all ports on local host. builder.SetIsOriginAllowed(origin => new Uri(origin).Host == "localhost"); builder.AllowAnyHeader(); builder.AllowAnyMethod(); }); }); var app = builder.Build(); app.UseRouting(); app.UseCors("AllowCorsPolicy"); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); app.Run();
To run the server-side application, run the following command:
consolecd ServerApp dotnet run
#Use Visual Studio Template
To create a back-end application from a Microsoft or DevExpress Template in Visual Studio, review the following help topics:
- Report Designer Server-Side Application (ASP.NET Core)
- Report Designer’s Server-Side Configuration (ASP.NET MVC)
#Client (Frontend) Part
The following steps describe how to configure and host the client part:
Create a new folder to store the client-side files (ClientSide in this example).
Create a package.json configuration in the ClientSide folder with the following content:
{ "name": "report-designer-example", "dependencies": { "devextreme-dist": "24.2-stable", "devexpress-richedit": "24.2-stable", "@devexpress/analytics-core": "24.2-stable", "devexpress-reporting": "24.2-stable", "ace-builds": "^1.3.3" } }
Note
Frontend and backend applications should use the same version of DevExpress controls.
Tip
The devexpress-richedit package enables the Rich Text Editor for the XRRich
Text control. You can exclude the package to reduce the node_modules folder size.Ensure that you have npm or Yarn package managers installed.
Navigate to the client application’s root folder and run the following command to install packages:
- if you have npm:console
npm install
if you have yarn:
consoleyarn install
- if you have npm:
Create a index.html file in the root folder. It is the View file in our model. Copy the following HTML code and insert it in this file:
<!DOCTYPE html> <html xmlns="https://www.w3.org/1999/xhtml/"> <head> <title></title> <script src="node_modules/jquery/dist/jquery.min.js"></script> <script src="node_modules/knockout/build/output/knockout-latest.js"></script> <!--Link DevExtreme resources--> <script src="node_modules/devextreme-dist/js/dx.all.js"></script> <link href="node_modules/devextreme-dist/css/dx.light.css" rel="stylesheet" /> <!-- Optionally (for intelligent code completion in the Expression Editor and Filter Editor) --> <script src="node_modules/ace-builds/src/ace.js"></script> <script src="node_modules/ace-builds/src/ext-language_tools.js"></script> <script src="node_modules/ace-builds/src/snippets/text.js"></script> <link href="node_modules/ace-builds/css/ace.css" rel="stylesheet" /> <link href="node_modules/ace-builds/css/theme/dreamweaver.css" rel="stylesheet" /> <link href="node_modules/ace-builds/css/theme/ambiance.css" rel="stylesheet" /> <!-- --> <!-- Link Rich Edit scripts and styles between DevExtreme and Reporting links --> <script src="node_modules/jszip/dist/jszip.min.js"></script> <script src="node_modules/devexpress-richedit/dist/dx.richedit.min.js"></script> <link href="node_modules/devexpress-richedit/dist/dx.richedit.css" rel="stylesheet" /> <!-- Link the Reporting resources --> <script src="node_modules/@devexpress/analytics-core/dist/js/dx-analytics-core.js"></script> <script src="node_modules/@devexpress/analytics-core/dist/js/dx-querybuilder.js"></script> <script src="node_modules/devexpress-reporting/dist/js/dx-webdocumentviewer.js"></script> <script src="node_modules/devexpress-reporting/dist/js/dx-reportdesigner.js"></script> <link href="node_modules/@devexpress/analytics-core/dist/css/dx-analytics.common.css" rel="stylesheet" /> <link href="node_modules/@devexpress/analytics-core/dist/css/dx-analytics.light.css" rel="stylesheet" /> <link href="node_modules/@devexpress/analytics-core/dist/css/dx-querybuilder.css" rel="stylesheet" /> <link href="node_modules/devexpress-reporting/dist/css/dx-webdocumentviewer.css" rel="stylesheet" /> <link href="node_modules/devexpress-reporting/dist/css/dx-reportdesigner.css" rel="stylesheet" /> </head> <!-- ... --> </html>
Note
The requirements and resources to deploy the control on the client are described in the Report Designer Requirements and Limitations document.
Create a example.js file in the root folder to provide data to the View. The JavaScript code in this file creates a designerOptions variable and activates the Knockout bindings. Copy the following code and insert it in the example.js file:
const host = 'http://localhost:5000/', reportUrl = "TestReport", designerOptions = { reportUrl: reportUrl, // The URL of a report that the Report Designer loads when the application starts. requestOptions: { // Options for processing requests from the Report Designer. host: host, // URI of your backend project. // If you use the ASP.NET Core backend: getDesignerModelAction: "/DXXRD/GetDesignerModel" // If you use the ASP.NET MVC backend: // invokeAction: "/ReportDesigner/Invoke", // Action to enable CORS. // getDesignerModelAction: "/ReportDesigner/GetReportDesignerModel"; } } new DevExpress.Reporting.Designer.DxReportDesigner(document.getElementById("designer"), designerOptions).render();
Modify the index.html file to specify the HTML template that uses the dxReportDesigner bindings with the designerOptions object as a parameter. Add the following code to the body section:
... <body> <div style="width:100%; height: 1000px" id="designer" ></div> <script type="text/javascript" src="example.js"></script></html> </body>
Host the client-side part on the web server. Start the Internet Information Services (IIS) Manager, right-click the Sites item in the Connections section, and select Add Website. In the invoked dialog, specify the site name, path to the client-side application root folder, and the website’s IP address and port.
Run the backend project.
- Open the website created in step 8, in the browser. In this example, the address is http://localhost:1000.
#Troubleshooting
When you start the application, you may encounter the following problems:
#Page Is Blank
The Report Designer page is blank. The following error message is displayed at the bottom of the page: The page is blank because the Report Designer failed to load the report. Consult the developer for assistance. Use development mode for detailed information.
Check the following:
- The backend application is up and running.
- The specified controller action path matches the back-end application type. If you use the ASP.NET Core backend, specify the
/DXXRD/GetDesignerModel
path; if you use the ASP.NET MVC backend, specify the/ReportDesigner/GetReportDesignerModel
path. - The backend application runs on the port specified in the
host
setting of the Report Designer component. - The application’s URI satisfies the CORS policy specified in your back-end application.
- The
reportUrl
value matches an existing report. For the back-end application, ensure that either the Reports folder contains a reportUrl.repx file or the ReportsFactory.Reports dictionary contains the reportUrl entry (if the back-end application originated from the DevExpress template). - The version of DevExpress npm packages should match the version of NuGet packages. Enable Development Mode to check for library version mismatch on every request to the server. For details, review the following help document: Server-Side Libraries Version.
Refer to the following help topic for more information: Troubleshooting.