display.grid.slice()



The slice() method returns an array of a portion of the records in a grid from begin to end (end not included).

The array is a copy of the records. Modifying the array does not modify the grid records.



Parameters

  1. begin (optional) - Zero-based index at which to begin the extraction. A negative index can be used, indicating an offset from the end of the sequence. slice(-2) extracts the last two elements in the sequence. If begin is undefined, slice begins from index 0.

  2. end (optional) - Zero-based index before which to end extraction. slice extracts up to but not including endFor example, slice(1,4) extracts the second record through the fourth record (records indexed 1, 2, and 3). A negative index can be used, indicating an offset from the end of the sequence. slice(2,-1) extracts the third record through the second-to-last record in the sequence. If end is omitted, slice extracts through the end of the sequence (total number of records)If end is greater than the length of the sequence, slice extracts through the end of the sequence.



Return Value

An array containing the extracted 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" and "description"   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.slice(2,4));   // The line above will log the following output: // [ { product: 2, description: "ITEM TWO" }, // { product: 3, description: "ITEM THREE" } ]