new Pager(pageropt, pagingHandleropt)
- Source:
Returns a newly created pager object with methods to navigate pages.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pager |
Object |
<optional> |
{page: 1, pageCount: 1}
|
Paging information object. |
pagingHandler |
Object |
<optional> |
{list: () => Promise.reject('No handler available')}
|
Paging handler object. The requirement for this object is that it has a list method. |
Members
nextPage
- Source:
Properties:
Name | Type | Description |
---|---|---|
nextPage |
string | The url to the next page. |
If there is no next page then this will be undefined.
page
- Source:
Properties:
Name | Type | Description |
---|---|---|
page |
number | Current page number |
pageCount
- Source:
Properties:
Name | Type | Description |
---|---|---|
pageCount |
number | The total number of pages available |
prevPage
- Source:
Properties:
Name | Type | Description |
---|---|---|
prevPage |
string | The url to the previous page |
If there is no previous page then this will be undefined.
query
- Source:
Properties:
Name | Type | Description |
---|---|---|
query |
object | Query parameters |
Query parameters are used for things like filtering and field selection. Used to guarantee that pages are from the same collection.
total
- Source:
Properties:
Name | Type | Description |
---|---|---|
total |
number | The total number of items available. |
This represents the total number of items available in the system. Note it is not the number of items on the current page.
Methods
getNextPage() → {Promise}
- Source:
Loads the next page in the collection if there is one. If no additional pages are available the Promise will reject.
Example
d2.models.organisationUnit
.list()
.then(collection => {
collection.pager.getNextPage()
.then(secondPageCollection => {
console.log(secondPageCollection.toArray());
});
});
Returns:
Promise that resolves with a new ModelCollection
containing the next page's data. Or rejects with
a string when there is no next page for this collection or when the request for the next page failed.
- Type
- Promise
getPreviousPage() → {Promise}
- Source:
Loads the previous page in the collection if there is one. If no previous pages are available the Promise will reject.
Example
d2.models.organisationUnit
.list()
.then(collection => {
collection.pager.goToPage(3)
.then(collection => collection.pager.getPreviousPage())
.then(secondPageCollection => {
console.log(secondPageCollection.toArray());
});
});
Returns:
Promise that resolves with a new ModelCollection
containing the previous page's data. Or rejects with
a string when there is no previous page for this collection or when the request for the previous page failed.
- Type
- Promise
goToPage(pageNr) → {Promise}
- Source:
Loads a specific page for the collection. If the requested page is out of the range of available pages (e.g < 0 or > page count) the Promise will reject with an error.
Example
d2.models.organisationUnit
.list()
.then(collection => {
collection.pager.goToPage(4)
.then(fourthPageCollection => {
console.log(fourthPageCollection.toArray());
});
});
Parameters:
Name | Type | Description |
---|---|---|
pageNr |
Number | The number of the page you wish to navigate to. |
Returns:
Promise that resolves with a new ModelCollection
containing the data for the requested page.
- Type
- Promise
hasNextPage() → {Boolean}
- Source:
Check whether there is a next page.
Returns:
Result is true when there is a next page, false when there is not.
- Type
- Boolean
hasPreviousPage() → {Boolean}
- Source:
Check whether there is a previous page.
Returns:
Result is true when there is a previous page, false when there is not.
- Type
- Boolean