JS Set Values for Expanded Cells

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

    1.1 Requirement

    Usually, we use setCellValue("cell", null, value) to set a cell value and this method applies only to fixed cells.

    To set the value of an expanded cell, e.g., the vertically expanded cell A1: setCellValue("A1", null, value), you will find that only the cell A1 has a value, but the expanded cells do not, so how to set the value of an expanded cell?

    Enter a number in the edit cell in each row, then the controlled cells will display 1 or 0 according to whether or not the number is greater than 10, as follows:


    1.2 Solution

    In the data entry, expanded cells can be divided into two categories by source: one is cells expanded directly from data columns and the other is cells expanded by inserting rows. The way of setting the value varies with the mode of expansion, which will be detailed below.

    II. Sample

    2.1 Directly expanded cells

    In an edit end event of a widget, dynamically pass the row number and column number to a JS function as parameters, use contentPane.setCellValue(col, row, value); to set a cell value.

    Both col and row begin from 0.

    Here, if the value of the edit cell is greater than 10, the controlled cell has a value of 1; otherwise, it has a value of 0.

    1) The template design interface corresponding to the figure above is as follows:

    2) Add an Edit End event to the widget of the textbox B2, input the row number row and the column number col, with the value of =row()-1 and =col() respectively:

     

    Input the JS code:

    if(this.getValue()>10){
      contentPane.setCellValue(col,row,1);
    }else{
      contentPane.setCellValue(col,row,0);
    }

    2.2 Cells expanded by inserting rows

    Add a Load End event in the Web Attributes of data entry, get the row number and column number of the cell being edited by using an event listener of FineReport, save them in a global variable and then get the row and column numbers from the Edit End event of the cell to set the cell value. See Get the Row Number of Cell Currently being Edited for how to get the row number and column number of a cell using an event listener of FineReport.

    1) Create a new template and add two text widgets in cells A2 and B2:

    2) Click Template>Web Attributes>Data Entry Settings to add a Load End event and the JS code is as follows:

    Note

    • a global variable must be preceded by Window.

    Input the JS code:

    contentPane.on("cellselect", function(td) {
      var row =contentPane.curLGP.getTDRow(td);
      var col =contentPane.curLGP.getTDCol(td);
      window.row=row;
      window.col=col;
    });

    3) Add an Edit End event to the widget of the cell A2 and the JS code is as follows:

    Note

    The row and column numbers obtained from the event listener begin from 1 and their values begin from 0.

    var value=this.getValue();
    contentPane.setCellValue(window.col,window.row-1,value);

    2.3 Preview

    Save the template and select Data Entry Preview. The preview effect on a PC is shown as below:

    1) Directly expanded cells

    2) Cells expanded by inserting rows

    III. Download templates

    1) Directly expanded cells

    1.cpt


    2) Cells expanded by inserting rows

    2.cpt


    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