Description
I’m using ERPNext/Frappe v16 and I’m trying to implement company-wise dynamic column visibility in the Purchase Order Items child table.
Example
Company A should display:
-
Item Code
-
Qty
-
Rate
-
Price List Rate
-
GST HSN Code
-
Discount %
-
Amount
Company B should display:
-
Item Code
-
Qty
-
UOM
-
Conversion Factor
-
Rate per Kg (custom field)
-
Amount
When the user changes the Company on the Purchase Order, the visible columns in the Items grid should update accordingly without reloading the form.
What I’ve tried
-
Implemented the logic in a Client Script.
-
Moved the same logic into a custom app JavaScript.
-
Triggered the logic on both
refreshandcompanyfield change events. -
Used the Grid API to toggle column visibility and refreshed the Items grid afterward.
The script executes successfully, and I confirmed that the underlying DocField metadata (such as the hidden property) is updated correctly. However, the rendered Items grid does not visually update—the same columns remain visible.
I also verified that:
-
There is no saved Assign Columns configuration.
-
The affected fields are not mandatory.
-
The JavaScript is loading and executing correctly.
Additionally, I tried forcing the grid to rebuild by:
-
Refreshing the grid.
-
Refreshing individual grid rows.
-
Rebuilding the grid header.
-
Clearing and rebuilding the grid DOM.
These approaches either had no effect or resulted in an inconsistent grid state.
Question
Is there a supported or documented way in Frappe/ERPNext v16 to force the Grid component to rebuild its visible columns after the initial render?
Or is dynamic column switching after the grid has been rendered not supported, meaning the recommended approach is to use static field visibility (depends_on, permissions, etc.) instead of changing grid columns programmatically?
Has anyone implemented company-specific Item grid columns in ERPNext v16 without reloading the form?
