Setting the Focus to Be a Widget by JS

  • Last update:July 25, 2025
  • Overview

    Problem

    During data entry preview, you may want the cursor to be automatically placed at a specific widget after page loading is finished, allowing you to edit the widget directly. This solution applies to scenarios where data entry shortcuts are set.

    动图1.gif

    Implementation Method

    You can use the relevant API in the corresponding event to realize the effect.

    Example One: Widget in a Cell

    Widget Adding

    Create a general report and add a widget, as shown in the following figure.

    1.png

    Loading End Event Setting

    1. Choose Template > Web Attribute > Data Entry Setting, set Following Settings to Set for This Template Separately, and add a Loading End event in Event Setting, as shown in the following figure.

    2.png

    The JavaScript code is as follows.

    var cell = _g().curLGP.getTDCell(0, 1);
    //Obtain cell A2.
    setTimeout(function() {
            _g().curLGP.selectTDCell(cell);
           _g().curLGP.editTDCell(cell);
           //Set the focus to cell A2.
    }, 50);

    Effect Preview

    Save the template and click Data Entry Preview. The following figure shows the effect.

    动图1.gif

    iconNote:
    The effect cannot be previewed on mobile terminals.

    Example Two: Widget on the Parameter Panel

    Widget Adding

    Create a general report and add a widget, as shown in the following figure.

    3.png

    After Initialization Event Adding

    1. Add an After Initialization event for the widget.

    4.png

    The JavaScript code is as follows.

    var a = this;
    //Obtain the current widget object.
    setTimeout(function() {
           a.editComp.focus();
           //Set the focus.
    }, 50)

    Effect Preview

    Save the template and click Data Entry Preview. The following figure shows the effect.

    动图2.gif

    iconNote: 
    The effect cannot be previewed on mobile terminals.

    Template Download

    Attachment List


    Theme: Data Entry
    • 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