Skip to content

Make a Grid Column Read-Only at Runtime

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


📌 Purpose

To conditionally make the "rate" column in a grid read-only, based on:

  • The current user is not 'ADMIN'
  • The selected GST Category (gstcatg) is 'B2B'

This setup ensures that users without admin privileges cannot modify rates on B2B invoices, thereby maintaining data integrity.


✅ Usage Scenario

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


🧠 Function Overview

function trn_inv_edit_afterload(entryid) {
    if (sys_username.toUpperCase() !== 'ADMIN' && $('#gstcatg').val() === 'B2B') {
        let ratecol = gridColNum('rate');
        const totalRows = hot.countRows();

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

        grid1.render(); // Apply changes visually
    }
}

👨‍💻 Developed By

Merci Development Team Think Simple 😊