Page tree
Skip to end of metadata
Go to start of metadata

The filter() method returns an array of all the records in the grid that satisfy the provided testing function.

 

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 true when the test condition is met.

 

Return Value

An array containing the extracted records that meet the testing function condition. 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 },
  { product: 4, description: "ITEM FOUR", quantity: 18 }
]);

// Find a record with quantity > 15
var records = display.mygrid.filter(function(record) {
  return (record.quantity > 15);
});
 
console.log(records);
 
// The line above will log the following output:
// [ { product: 2, description: 'ITEM TWO', quantity: 20 },
//   { product: 4, description: 'ITEM FOUR', quantity: 18 } ]