FR - Calculated Field Rules on Grids

On this forum you can see a list of new features requested by users and you can also cast your own vote (you need to login to vote).
Post Reply
PointsWell
Posts: 1451
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

FR - Calculated Field Rules on Grids

Post by PointsWell »

There is a need for an additional presentation rule to control whether a attribute is editable or calculated based on calculation and for it to be able to control access in a query grid.

For example

I have a query that a user edits inline. There are three fields of interest:
  • Qty
  • List
  • Receipts
Depending on the type of contract (which is driven by a prior selection in the grid) the user has to enter
  1. Qty and List to determine Receipts, or
  2. Qty and Receipts to determine List
The grid may contain both contract options at the same time, so it's not possible to have multiple grid structures to alter the order and editablility of the fields.

At the moment the user is able to enter any of the three fields and modify these. It can be controlled with additional business rules to say if the contract is option 1 from above and the Receipts field has been changed then revert the Receipts back to Qty * List, but it would be a nicer experience if the field was not editable in the first place.

I briefly thought about Protect Rules, but Protect would (depending on the order of implementation) prevent the calculation being carried out at all or would prevent edits to the field later.

These presentation rules (Calculated v Editable) would apply on forms as well I would imagine.
nhofkes
Posts: 78
Joined: Mon Sep 07, 2020 6:03 am
Location: Netherlands

Re: FR - Calculated Field Rules on Grids

Post by nhofkes »

As a sub-optimal solution (since it is far from low-code approach), it's possible to control editing of fields in an inline-editable grid through a render script added to the grid. As an example, below the code that I am using to prevent editing of other fields for a particular row if the first (in this particular case most important field) has not yet been supplied.

Code: Select all

// Render script for the grid (which is inline editable)
const grid = widget;
grid.bind("beforeEdit", onBeforeEdit);

// Event handler for cell edit
function onBeforeEdit(e) {
    let cell = grid.current ();
    if (cell.length == 1) {
        let colIndex = grid.cellIndex(cell);
        if (colIndex >= 0) {
            let columnName = e.sender.columns[colIndex].field;
            if (columnName != 'sc_InstrumentName' && (e.model['sc_InstrumentName'] == "" || e.model['sc_InstrumentName'] == null) ) {
                e.preventDefault(); // this prevents editing of the cell
            }
        }
    }
}
In a similar approach you could prevent editing of a field depending on the contents of other fields within the row. If you would want to make editing contingent on the content of another field which is not part of the visible cells in the grid, this can be done by putting that field in a column which is hidden; in that case it isn't shown the grid but you can still access the field through e.model[fieldname] in the event handler.
Niels
(V9.0 build 3241 - MariaDB - Windows)
Post Reply