Pagination Helpers
This tutorial is about the new Pagination Helpers available in Cortex 1.8.6+.
When working with lists, it is often important to page through results. The recommended approaches to working with lists through the API are outlined here.
However, the Cortex SDK makes this quite simple with pagination helpers.
The following examples illustrate how to paginate through a list of c_prescription
instances.
For information on how to create custom cortex objects such as the example c_prescription
object, see Data Model Setup.
For more information on working with your Cortex Objects, see Cortex Objects.
1. Using the Pagination Helper
This is how an instance of MDPaginationHelper
is created and initialized:
// Optionally, custom API parameters (query parameters) can be specified; and the paginator will include those in the queries as well.
JsonObject refills = new JsonObject();
refills.addProperty("$lt", 5);
JsonObject where = new JsonObject();
where.add("c_refills", refills);
//Create the paginator using the
ObjectPaginationHelper paginator = new ContextObjectPaginationHelper("c_prescriptions", 5, null, APIParameterFactory.parametersWithWhere(where, null));
paginator.loadNextPage(new ObjectsListCallback<Prescription>() {
@Override
public void call(List<Prescription> results, boolean hasMore, Fault fault) {
//..
}
});
// Optionally, custom API parameters (query parameters) can be specified; and the paginator will include those in the queries as well.
val refills = JsonObject()
refills.addProperty("\$lt", 5)
val where = JsonObject()
where.add("c_refills", refills)
//Create the paginator using the
val paginator = ContextObjectPaginationHelper("c_prescriptions", 5, null, APIParameterFactory.parametersWithWhere(where, null))
paginator.loadNextPage { results, hasMore, fault ->
//..
}
Updated 4 months ago