display.grid.forEach()



The forEach() method executes a provided function once for each grid record.



Parameter

  1. Callback function that receives the following arguments:

    1. Record object - the object is a copy of the record; therefore, modifying the object will not change the record in the grid

    2. Index - the zero-based index of the current grid record being processed

    3. Records array - array representing all of the grid records



 Example

pjs.defineDisplay("display.json"); // assume display.json defines mygrid with fields named "product", "description", and "quantity" display.mygrid.addRecords([ { product: 1, description: "ITEM ONE", quantity: 15 }, { product: 2, description: "ITEM TWO", quantity: 20 }, { product: 3, description: "ITEM THREE", quantity: 12 }, { product: 4, description: "ITEM FOUR", quantity: 18 } ]); // Calculate quantity total using the forEach() method var total = 0; display.mygrid.forEach(function(record) { total += record.quantity; });