Reading data in the IG

This turned into a miniseries. First it was about focusing on a cell and then on entering the cell in edit mode, but I figure there is a related thing one might want to do. You could want to read the data in a cell once the Interactive Grid (IG) has been loaded.

Maybe you need it for some other processing or you want to present something in the IG also in another region. Say that you show the user the last three times a job was executed and you want to suggest the next start time to be based on the longest time they took. Sure you could go back to the database and pick it up with a MAX(), but you already have the data read for the IG, so why add more load on the database when the data is already available.

To do this we stay very close to the previous iterations. It is a Dynamic Action on the Interactive Grid region for the event Page Load [Interactive Grid]. The true action is a Execute JavaScript that has this code in it.

var ig = apex.region("ABC").widget().interactiveGrid("getViews","grid");
var rec = ig.model.recordAt(2);
var val = ig.model.getValue(rec,"ORDER_DATETIME");

apex.message.alert( "Date = " + val );

ABC is the static ID of the IG. Wi grab the third record in the IG and in it we get the value for the ORDER_DATETIME column. We could get it by just accessing the field in the record by index, but getting it through the model and stating the name of the column makes for much more readable code to me.

Then apex.message.alert is used to pop up an alert on the screen. The built in alert does not allow for the message to be dynamic, that is why doing it in JavaScript is used here.

If you are like me though, you may prefer such data to be printed. If we change the last line to this, it will go to your JavaScript concole.

console.log( "Date = " + val ); 

If you want to control so it is only emitted when debug of a certain level is enabled, replace it with this.

apex.debug.info("Date = " + val);

With this you can retrieve data from the records in the IG, either to present it or to evaluate and make decisions based on the data the user can see.

There are many use cases for these techniques. Being able to act on data the user is actually seeing let’s you customise their experience in ways not possible to achieve on the server side.

Leave a Comment

Your email address will not be published. Required fields are marked *