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
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
.end (optional) - Zero-based index before which to end extraction.Â
slice
 extracts up to but not includingÂend
. For 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" } ]