Column "Read-only" Function (Interactive Grid #7)

Column "Read-only" Function (Interactive Grid #7)

Introduction

Let's have a look at cheat number seven :-)

#7 Column "Read-only" Function

This tip mostly comes Out-of-the-Box from Oracle APEX. It is so simple that we don't think about it, because as a developer we often think too complicated.

Ok, what do we want? The target is to lock cells in the interactive grid in case that another cell in the same row has a predefined value. To realize this, APEX has the Read-only function, which we can use perfectly here.

But we also have another attribute available for the interactive grid -> Execute.

The options for the Execute attribute are "For Each Row" and "Once".

The following is written in the documentation:

If you refer to Columns in your read only condition, you must specify For Each Row in order for the condition to be evaluated for each row of the Interactive Grid. Otherwise, set to Once to evaluate the condition only one time for the region.

By default the attribute is "Once", although the documentation says that you have to specify "For Each Row" in the interactive grid.

Enough theory...let's start with a small demo app.

For this example we use the sample dataset "EMP / DEPT", in which we have the tables "EMP" and "DEPT". Then we create an application with an interactive grid or create a new page in an existing application. As source we use the table "EMP".

Now we have an interactive grid where we can add "Read-only" columns. To do this, we go to the page designer and click for example the column "Sal". Next go to the Read-Only attribute and set for this column the Type to "Item != Value", Item to "Deptno", Value to "30" and Execute to "For each Row".

When the application is started now, we can already see the result that the cells can only be edited in Department 30. However, if the department is changed now, our read-only condition does not change. To do this we need a dynamic action that saves and re-initializes the values of the grid.

For that, we create a new dynamic action that is triggered by an change event. The Selection Type must be "Column(s)" and the column "DEPTNO". Then we create a "True" action that Execute JavaScript Code and enter the following in the Code-Editor:

apex.message.confirm( "Do you really want to change the Department?", function( okPressed ) {
    if( okPressed ) {
        apex.region("my_ig").call("getActions").invoke("save");
    }
});

First line is only a message box that asked you if you really want to change the value.

If you clicked "OK", the Interactive Grid save the modified cells by calling the "Save" event (line 3).

Please note that "my_ig" is the static id from the Interactive Grid.

So don´t forget to set the static id :-)

So, that´s it...and here is the demo app.

We hope the tips and tricks will help you.

If you have questions or suggestions, please leave us a comment