Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Report Designer Integration (Node.js Package Manager)

  • 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
  • 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:

  1. Install DevExpress ASP.NET Core project templates from nuget.org:

    dotnet new install DevExpress.AspNetCore.ProjectTemplates
    
  2. Create a back-end Reporting application:

    console
    dotnet new dx.aspnetcore.reporting.backend -n ServerApp
    

    You can use the following parameters to see available command options: -? | -h | --help.

  3. 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 the UseRouting method and before any MVC-related code. Place the UseCors method before the UseMvc or UseEndpoints 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();
    
  4. To run the server-side application, run the following command:

    console
    cd 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:

#Client (Frontend) Part

The following steps create the client part, install the required npm packages and create a bundle with Webpack:

  1. Install Node.js and npm if they do not exist on your machine.
  2. Install the Webpack CLI globally with the following commands:

    console
    npm install -g webpack
    npm install -g webpack-cli
    
  3. Create a folder for a client-side project. In this example, the folder’s name is ClientSide.

  4. Add a package.json configuration file to the created folder and list the following third-party packages the Web Report Designer requires:

    {
        "name": "report-designer",
        "version": "1.0.0",
        "dependencies": {
            "devextreme": "24.2-stable",
            "devexpress-richedit": "24.2-stable",
            "@devexpress/analytics-core": "24.2-stable",
            "devexpress-reporting": "24.2-stable",
            "mini-css-extract-plugin": "^2.9.1",
            "css-loader": "^7.1.2"
        },
        "devDependencies": {
            "html-loader": "~0.5.4",
            "webpack": "^5.0.0"
        }
    }
    

    Note

    Frontend and backend applications should use the same version of DevExpress controls.

    Tip

    Add the devexpress-richedit package if you want to enable the Rich Text Editor for the XRRichText control.

  5. Navigate to your folder, open the console and run the command below to install packages:

    console
    npm install
    

    You can find all the libraries in the node_modules folder after installation is completed.

  6. Create a webpack.config.js file and specify configuration settings as shown below. Define the index.js file as the bundle’s entry point (this file is created later) and the bundle.js file as the output file.

    var path = require('path');
    var webpack = require('webpack');
    const MiniCssExtractPlugin = require('mini-css-extract-plugin');
    
    module.exports = {
        entry: './index.js',
        output: {
            filename: 'bundle.js'
        },
        mode: "development",
        module: {
            rules: [
                {
                    test: /\.html$/,
                    loader: "html-loader" 
                },
                {
                    test: /\.css$/,
                    use: [
                        MiniCssExtractPlugin.loader, 
                        'css-loader'    // Interprets `@import` and `url()` like `import/require()` and resolves them.
                    ]
                }
            ]
        },
        plugins: [
            new MiniCssExtractPlugin({
                filename: 'styles.css' // Output CSS file name.
            })
        ]
    };
    
  7. Create a View file (the index.html file in this example) and specify this View’s HTML template. In the body section, use the dxReportDesigner binding with the designerOptions parameter and link the bundle script file (bundle.js) specified in the previous step.

    <!DOCTYPE html>
    <html>
        <head>
             <!-- ... -->
        </head>
    
        <body>
            <div style="width:100%; height: 1000px" id="designer"></div>
            <!-- Include the bundle script -->
            <script type="text/javascript" src="dist/bundle.js" charset="utf-8"></script>
        </body>
    </html>
    
  8. Add a new JavaScript file (index.js) to provide data to the View. Link the required modules, create a designerOptions variable and activate the Knockout bindings.

    var ko = require('knockout');
    import { DxReportDesigner } from 'devexpress-reporting/dx-reportdesigner'
    
    require('./style.css');
    require('devexpress-reporting/dx-reportdesigner')
    require('devexpress-reporting/dx-richedit')
    
    const 
        // URI of your backend project.
        host = 'http://localhost:5000/', 
        reportUrl = "TestReport";
        var designerOptions = {
                reportUrl: reportUrl, // The URL of a report that is opened in the Report Designer when the application starts.
                requestOptions: { // Options for processing requests from the Report Designer. 
                host: host, 
                // If you use the ASP.NET Core backend:
                getDesignerModelAction: "/DXXRD/GetDesignerModel"
                // If you use the ASP.NET MVC backend:
                // getDesignerModelAction: "/ReportDesigner/GetReportDesignerModel"
                },
        };
    new DxReportDesigner(document.getElementById("designer"), designerOptions).render(); 
    
  9. Create a new style.css file with the following content:

    @import url("node_modules/ace-builds/css/ace.css");  
    @import url("node_modules/ace-builds/css/theme/dreamweaver.css");  
    @import url("node_modules/ace-builds/css/theme/ambiance.css");  
    @import url("node_modules/devextreme-dist/css/dx.light.css");
    @import url("node_modules/devexpress-richedit/dist/dx.richedit.css");
    @import url("node_modules/@devexpress/analytics-core/dist/css/dx-analytics.common.css");
    @import url("node_modules/@devexpress/analytics-core/dist/css/dx-analytics.light.css");
    @import url("node_modules/@devexpress/analytics-core/dist/css/dx-querybuilder.css");
    @import url("node_modules/devexpress-reporting/dist/css/dx-webdocumentviewer.css");
    @import url("node_modules/devexpress-reporting/dist/css/dx-reportdesigner.css");
    

    Link this file in the index.html file’s head section.

    ...
    <head>
        <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    ...
    
  10. Run the following command to create the bundle:

    console
    webpack
    
  11. Host your client-side part on the web server.

    For instance, 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 folder with the client-side functionality, and the website’s IP address.

    Host the Example with IIS Manager

  12. For the example to work correctly, you should first run a backend project in Visual Studio, and then, run a client part.

#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.