display.grid.getRecordCount()
Description
display.grid.getRecordCount() returns the total number of records currently in the grid. The count includes every record loaded with display.grid.write(), display.grid.addRecords(), or the other loading methods, whether or not the record is visible on the current page of the grid.
Syntax
display.gridName.getRecordCount()Parameters
None.
Return Value
Number - The number of records in the grid; 0 when the grid is empty.
Examples
Example 1: Count the Records in a Grid
Loads four records and logs the count.
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.addRecords([
{ product: 1, description: "ITEM ONE" },
{ product: 2, description: "ITEM TWO" },
{ product: 3, description: "ITEM THREE" },
{ product: 4, description: "ITEM FOUR" }
]);
console.log(display.mygrid.getRecordCount()); // 4Example 2: Show a Message When the Grid Is Empty
Loads the grid from a query and, when no rows were returned, displays a message instead of an empty 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, and PRQTY, and an output field named msg on the screen.
pjs.defineDisplay("display.json"); // Object name defaults to "display"; display.json defines mygrid
var rows = pjs.query("SELECT prid AS product, prname AS description, prqty AS quantity FROM productsp");
display.mygrid.replaceRecords(rows);
if (display.mygrid.getRecordCount() === 0) {
msg = "No products were found.";
}
else {
msg = display.mygrid.getRecordCount() + " products listed.";
}
display.screen.execute();