Loading TOC...

AccessPlan.prototype.offset

AccessPlan.prototype.offset(
   $start as String
) as ModifyPlan

Summary

This method returns a subset of the rows in the result set. The start parameter specifies the index in the result set to use as the starting point for the return, followed by the remaining rows up to the number specified by the prototype.limit method.

A common pattern is to page over a result set by using a op.param placeholder parameter for the start and specifying the starting value in bindings for op.result. This approach reuses the cached query instead of recalculating the query on each request.

Parameters
$start The index in the result set to use as the starting point.

Usage Notes

limit is a method of the following classes:

Example


// Calculate the total expenses for each employee and return two results in order 
// of employee number, starting with the third result.

const op = require('/MarkLogic/optic');

const employees = op.fromView('main', 'employees');
const expenses = op.fromView('main', 'expenses');
const totalexpenses  = op.col('totalexpenses');
const Plan =
employees.joinInner(expenses, op.on(employees.col('EmployeeID'), expenses.col('EmployeeID')))   
   .groupBy(employees.col('EmployeeID'), ['FirstName', 'LastName', expenses.col('Category'),
    op.sum(totalexpenses, expenses.col('Amount'))])
   .orderBy('EmployeeID')
   .offset(2)
   .limit(2)
Plan.result(); 

  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.