Grid API

Grid API

Overview

The Grid API contains the methods that a Profound.js module uses to load, read, change, and remove the records of a grid (subfile) in a Rich Display File. A grid object is created for every grid in a display file defined with pjs.defineDisplay(), and it is referenced through the display object using the grid's record format name property. For example, if display.json contains a grid whose record format name is mygrid, the grid object is display.mygrid.

The methods fall into two styles:

  • Subfile-style methods - write(), update(), getRecord(), readChanged(), and clear() work one record at a time through the program's global fields (or a data structure), in the same way as the RPG WRITE, UPDATE, CHAIN, READC, and SFLCLR operations. These are used heavily in applications converted from RPG.

  • Array-style methods - addRecords(), getRecords(), find(), filter(), sort(), and so on work with JavaScript objects and arrays, and are modeled on the standard JavaScript Array methods. Each record is a JavaScript object with one property for each field in the grid.

The methods are listed below, grouped by what they do. Each method has its own page with the syntax, parameters, return value, and working examples.

Loading and Clearing the Grid

Reading and Updating Records

Removing Records

Searching, Testing, and Transforming Records

Working with Record Objects

The array-style methods pass records to your code, and accept records from your code, as plain JavaScript objects. Keep the following in mind:

  • Property names - Each property is named after a field in the grid. When a record object is added to the grid, any grid field that has no matching property is stored as blank.

  • Records are copies - Each record object is a copy of the grid record. Numeric fields (packed, zoned, and float) are returned as JavaScript numbers, character fields as strings, and indicator fields as the strings "1" and "0". Changing the object does not change the record in the grid. To change the grid, use a method that writes back to it, such as applyMap(), replaceRecords(), or update().

  • Indexes and relative record numbers - Indexes used by the array-style methods are zero-based, so the first record is index 0. Relative record numbers used by the subfile-style methods are 1-based, so the first record is RRN 1.

  • The display must be open - All grid methods require the display file to be open; calling them on a closed display throws error 1211 (I/O operation to a closed file).

  • Asynchronous methods - The subfile-style I/O methods and the methods that take a callback function are asynchronous. Inside a Profound.js module the framework waits for them automatically, so they are called exactly as shown in the examples. The callback passed to a method such as forEach() or find() may itself be an async function; the records are then processed one at a time, in order.


Related Pages