display.grid.push()
Description
display.grid.push() adds one or more records to the end of a grid. Each record is a JavaScript object with one property for each field in the grid. It is modeled on the JavaScript Array.prototype.push() method.
If the first argument is an array, it is treated as an array of records and passed to display.grid.addRecords(). To insert at the beginning of the grid use display.grid.unshift(), and to insert at a given position use display.grid.insert().
Syntax
display.gridName.push(record)
display.gridName.push(record1, record2, ...)Parameters
Record (Object) - A JavaScript object with properties representing the fields in the grid. A grid field with no matching property is stored as blank.
Additional records (Object, optional) - One or more additional record objects to add after the first one.
Return Value
Nothing is returned.
Examples
Example 1: Add Records One at a Time and Several at Once
Adds one record with the first call and two more with the second call.
Prerequisite: a Rich Display File named display.json with a record format named screen that contains a grid whose record format name is mygrid, with the fields product and description bound to its columns.
pjs.defineDisplay("display.json"); // Object name defaults to "display"; display.json defines mygrid
display.mygrid.push({ product: 1, description: "ITEM ONE" }); // Add 1 record
display.mygrid.push( // Add 2 records
{ product: 2, description: "ITEM TWO" },
{ product: 3, description: "ITEM THREE" }
);
console.log(display.mygrid.getRecordCount()); // 3Example 2: Build a Grid Inside a Loop
Reads a table one row at a time with the pjs.query() API and pushes a record for each row that passes a business rule, so that the rule can use values that are not in the grid.
Prerequisite: a Rich Display File named display.json with a record format named screen that contains a grid whose record format name is mygrid, with the fields product, description, and quantity bound to its columns. The example also assumes a table PRODUCTSP with the columns PRID, PRNAME, PRQTY, and PRSTATUS.
pjs.defineDisplay("display.json"); // Object name defaults to "display"; display.json defines mygrid
var rows = pjs.query("SELECT prid, prname, prqty, prstatus FROM productsp ORDER BY prid");
display.mygrid.clear();
rows.forEach(function(row) {
if (row.prstatus !== "D") { // Skip discontinued products
display.mygrid.push({
product: row.prid,
description: row.prname,
quantity: row.prqty
});
}
});
display.screen.execute();