Predefined Export Button by JS

  • Last update:July 11, 2025
  • Overview

    Problem

    During export file name customization by JS, you can customize an export button for exporting files with custom names by JS on the parameter panel of a template. However, it is cumbersome for you to achieve the same export function in multiple templates by repetitively writing JS codes. Therefore, you can predefine an export button that can be directly dragged to the parameter panel for use whenever needed, as shown in the following figure.

    Implementation Method

    You can customize an export button to which a JS event is added in Widget Management to realize the export function.

    Example

    Predefined Button

    1. Choose Server > Widget Management on the menu bar of the designer, as shown in the following figure.

    2. Create a widget and set attributes for the widget, as shown in the following figure.

    ① Click + to create a widget.

    ② Double-click Predefined WidgetX and modify the name to Export.

    ③ Select Button Widget from the drop-down list of Select Widget.

    ④ Set Widget Name to export.

    ⑤ Set Button Type to Common and set Button Name to Export.

    3.png

    3. Click Event, add parameters and the JS code, and then click OK in the lower left corner, as shown in the following figure.

    The following shows the parameters.

    Set the value of the parameter servletURL to the formula servletURL.

    Set the value of the parameter reportName to the formula reportName.

    Set the value of the parameter exportName to the formula indexofarray(split(indexofarray(REVERSEARRAY(split(reportName,"/")),1),".c"),1)+"_"+format(now(),"yyyyMMddHHmm"). This formula is used to customize the file name.

    The JavaScript code is as follows.

    iconNote:
    The default name of the exported file generated by the code is Template Name_Export Time (specified to the minute).
    // Define the report URL by obtaining the path and name of the corresponding template with built-in parameters servletURL and reportName.
    var url=servletURL+"?viewlet="+reportName;
    // Traverse the parameter panel widgets to obtain their corresponding values.
    $.each(this.options.form.name_widgets,function(i,item) {
          if(item.options.type!== 'label'&&item.getName()!="PARA"&&item.getName()!="SEARCH"&&item.getName()!="EXPORT") {
          url+="&"+item.getName()+"="+item.getValue();
        }
    });
    // Add printing parameters to the URL.
    url+="&format=excel&extype=simple&__filename__="+exportName;
    url += "&format=excel&extype=simple&filename=" + exportName;window.location = encodeURI(encodeURI(url)); // Encode and export the file.

    Button Use

    Open a template, for example, the built-in template GettingStartedEN.cpt in %FR_HOME%\webapps\webroot\WEB-INF\reportlets.

    1. On the toolbar of the parameter panel, click the small triangle icon to view the custom export button, press the button, and drag the button to the parameter panel for use, as shown in the following figure.

    2. Save the template and click Pagination Preview. After you query the report content, click the Export button to export the Excel file. The following figure shows the effect.

    iconNote:
    The effect cannot be previewed on mobile terminals.

    Template Download

    For details, you can download the template Predefined Export Button by JS.cpt.

    Attachment List


    Theme: Report Application
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy