display.grid.map()



The map() method creates a new array of records with the results of calling a provided function on every element in the grid records array.



Parameter

  1. Callback function that receives the following arguments:

    1. Record object with properties for each field 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

The function must return a record object.



Return Value

An array containing the new records. Each array element is a JavaScript object with properties for each field in the grid.



 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 } ]); var records = display.mygrid.map(function(record) { record.quantity += 1; return record; });   console.log(records);   // The line above will log the following output: // [ { product: 1, description: "ITEM ONE", quantity: 16 }, // { product: 2, description: 'ITEM TWO', quantity: 21 }, // { product: 3, description: 'ITEM THREE', quantity: 13 } ]