Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

The sort() method sorts records in a grid based on a provided compare function or on a field name.

 

Parameters

  1. Compare function - a function that received 2 grid records to compare. If the function returns less than 0, the first record will come first in the sort order. If the function returns greater than 0, the second record will come first in the sort order

    OR
  1. Field name - Name of a field in the grid to sort by
  2. Descending (optional) - True or false flag indicating whether the sort should be in descending order. If omitted, false is assumed.

 

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 }
]);

// Sort records by quantity in descending order
display.mygrid.sort("quantity", true);

// Sort records by quantity using a compare function
display.mygrid.sort(function(record1, record2) {
  if (record1.quantity > record2.quantity) return 1;
  else return -1;
});
  • No labels