JS Predefine an Export Button

  • Last update:  2020-12-28
  • I. Overview

    1.1 Problem Description

    The built-in export button in the toolbar do not support customizing the name of the exported file. You can use JS to customize the name just like the method in JS Customize Export File Name.

    However, if many templates need to implement this function, it is better to set a predefined export button which can be used by all templates. How to achieve this?

    1.2 Solution

    1) Traverse the widgets in the parameter pane to obtain the corresponding parameter values.

    2) Obtain the path of the corresponding template through parameters named servletURL and reportName.

    II. Steps

    2.1 Create a new widget and add attributes

    1) Select Server > Widget Manager.

    image.png

    2) Follow the steps to add a button

    • Click image (1).png  to add a new widget

    • Double click to modify widget name to export

    • Set widget type to Button

    • Button type is Common and button name is Export

    image (2).png

    3) Click Event, add parameters and JS codes, and click OK.

    image (3).png 

    Parameters are as follows:

    servletURL: servletURL

    reportName: reportName

    exportName: indexofarray(split(indexofarray(REVERSEARRAY(split(reportName,"/")),1),".c"),1)+"_"+format(now(),"yyyyMMddHHmm")


    Tips: The default export file name implemented by this code is: template name_export time, which is determined by exportName. Here you can customize the export name by changing the parameter value.

    The JS code is:

    var url=servletURL+"?viewlet="+reportName;
    $.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();
        }
    });
    url+="&format=excel&extype=simple&__filename__="+exportName;
    window.location=(FR.cjkEncode(url));

     

    2.2 Add the cusomized button to parameter pane

    Edit the parameter pane. In the toolbar, click on the small triangle and you will see the customized export button. Press and hold it to drag it to the parameter pane.

    image (4).png

            

    2.4 View results

    Preview the template and click the customized button.

    image (5).png

    Tips:Not support mobile devices.

    III. Completed Template

    Attachment List


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