Skip to content

Auto Replicate a column value to other rows in Grid¶

Purpose¶

This code simplifies a common data entry task in grids where the column value entered in the first row needs to be automatically replicated to all the subsequent filled rows below it.


Use Case¶

When entering transaction data, it is often required that the rate entered in the first row applies to all other rows (where UOM is filled). This reduces manual entry and ensures consistency across the dataset.


🧠 Function Overview¶

function trn_yarnschlg_rate_postvalid(hotrow, hotcol, colname, oldval, newval) {
   let value = parseFloat(eval(newval));

   if (value > 0 && hotrow == 0) {  // only do this for the rate of the first row
      for (var z = 1; z <= maxrows - 1; z++) {  //maxrows variable is a Merci variable which stores total rows of the current grid. Note: Last row is reserved for totals...!!
          let uom = grid1.getDataAtCell(z, gridColNum('uom'));  //fetch the UOM value of next row. See: Loop starts from row 1 (z=1, where 1 is second row)
          if (uom !== '' && uom !== null){
             grid1.setDataAtCell(z, gridColNum('rate'), value);
          } 
          else{
             break;
          }
      }
   }
}

Explanation¶

  • Trigger: This function is triggered after the rate field is validated.
  • Condition: If the user enters a valid rate (value > 0) in the first row only (hotrow == 0).
  • Logic:
  • Loop through all the rows starting from index 1 (second row).
  • Check if the UOM (Unit of Measurement) is filled in that row.
  • If yes, copy the rate from the first row to that row.
  • If UOM is empty or null, the loop breaks — assuming the data ends there.

Notes¶

  • This logic ensures no overwrite happens on empty rows.
  • This functionality helps save time and maintain consistency in data entry.


Author¶

Merci Development Team
Think Simple 😊