JS Modify a Column Value of Selected Rows at One Click

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

    1.1 Requirement

    In some cases, we need to select a batch of records and then modify values in a column all at once. For example, batch approval or batch cancellation of approval is often required for selected records, as it takes more time and energy to click the Approval button for each row. Such batch operations can be enabled in reports via JavaScript, with the effect shown below:

     

     

    1.2 Solution

    Traverse checkboxes through JavaScript, judge whether they are checked, fetch checked row numbers and then use contentPane.setCellValue(col,row,value) for batch setting.

    II. Sample

    2.1 Add Button widgets

    Add Button widgets named ‘Terminate the order’ and ‘Cancel termination order’ to D1 and F1 respectively, as shown below in D1:

     


    2.2 Add an After Initialization event

    Add an After Initialization event to the Checkbox widget in A3, as shown below:

     

    Input the following JavaScript codes:

    if (!window.lineboxes) {
         window.lineboxes = [];

    lineboxes[lineboxes.length] = this;

     

    2.3 Add a click event

    Add a click event to the button in D1, as shown below:

     

    Input the following JavaScript codes:

    if (window.lineboxes) {
           var cells = [];
           for (var i = 0; i < lineboxes.length; i++) {
                  if (lineboxes[i].selected()) {
                         var cr = FR.cellStr2ColumnRow(window.lineboxes[i].options.location);
                         //Fetch the rows and columns in which checked checkboxes are located
                         _g().setCellValue(7, cr.row, 'N');
     //Assign values to these rows and columns one by one; here, 7 is a column number and means column H
               }
           }

    Add a click event to the button in D1 by inputting the following JavaScript codes:

    if (window.lineboxes) {
           var cells = [];
           for (var i = 0; i < lineboxes.length; i++) {
                  if (lineboxes[i].selected()) {
                         var cr = FR.cellStr2ColumnRow(window.lineboxes[i].options.location);
                         //Fetch the rows and columns in which checked checkboxes are located
                         _g().setCellValue(7, cr.row, 'Y');
     //Assign values to these rows and columns one by one; here, 7 is a column number and means column H
                  }
           }
    }

     

    2.4 Preview

    Save the template and click [Data Entry Preview]. The effect is shown below:

     

    III. Download the template

    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