Skip to content

Make a grid column readonly at runtime¶

Use this functionality when a specific column in a grid needs to be made read-only conditionally during the editing of an entry.


📌 Purpose¶

To make the "rate" column in a grid read-only based on a condition — specifically: - When the current user is not 'ADMIN' - And the selected GST Category (gstcatg) is 'B2B'

This ensures users with restricted privileges cannot alter rates for B2B invoices.


✅ Usage Scenario¶

During the editing of a transaction entry, if the GST category selected is B2B, and the logged-in user is not 'ADMIN', the "rate" column for all rows in the grid is made read-only.


🧠 Function Overview¶

function trn_inv_edit_afterload(entryid) {
   if (sys_username.toUpperCase() !== 'ADMIN' && $('#gstcatg').val() == 'B2B'){
      let ratecol = gridColNum('rate');
      const totalRows = hot.countRows(); // Get the total number of rows in the table

      for (let row = 0; row < totalRows; row++) {
          grid1.setCellMeta(row, ratecol, 'readOnly', true);
      }

      grid1.render(); // Re-render the table to apply changes
   }
}

Author¶

Merci Development Team
Think Simple 😊