Class PagingModel
A page model is a helper class to apply a pages to a collection of elements or an iterator of elements and supports creating URLs for continued paging through the elements.
The page model is intended to be initialized with the collection or iterator, than the paging position is applyed and than the elements are extracted with getPageElements().
In case the page model is initialized with a collection the page model can be reused multiple times.
| Constant | Description |
|---|---|
| DEFAULT_PAGE_SIZE: Number = 10 | The default page size. |
| MAX_PAGE_SIZE: Number = 2000 | The maximum supported page size. |
| PAGING_SIZE_PARAMETER: String = "sz" | The URL Parameter used for the page size. |
| PAGING_START_PARAMETER: String = "start" | The URL parameter used for the start position. |
| Property | Description |
|---|---|
count: Number (read-only) | Returns the count of the number of items in the model. |
currentPage: Number (read-only) | Returns the index number of the current page. |
empty: Boolean (read-only) | Identifies if the model is empty. |
end: Number (read-only) | Returns the index of the last element on the current page. |
maxPage: Number (read-only) | Returns the maximum possible page number. |
pageCount: Number (read-only) | Returns the total page count. |
pageElements: Iterator (read-only) | Returns an iterator that can be used to iterate through the elements of the current page. |
| pageSize: Number | Returns the size of the page. |
| start: Number | Returns the current start position from which iteration will start. |
| Constructor | Description |
|---|---|
| PagingModel(Iterator, Number) | Constructs the PagingModel using the specified iterator and count value. |
| PagingModel(Collection) | Constructs the PagingModel using the specified collection. |
| Method | Description |
|---|---|
| static appendPageSize(URL, Number) | Returns an URL containing the page size parameter appended to the specified url. |
| appendPaging(URL) | Returns an URL by appending the current page start position and the current page size to the URL. |
| appendPaging(URL, Number) | Returns an URL by appending the paging parameters for a desired page start position and the current page size to the specified url. |
| getCount() | Returns the count of the number of items in the model. |
| getCurrentPage() | Returns the index number of the current page. |
| getEnd() | Returns the index of the last element on the current page. |
| getMaxPage() | Returns the maximum possible page number. |
| getPageCount() | Returns the total page count. |
| getPageElements() | Returns an iterator that can be used to iterate through the elements of the current page. |
| getPageSize() | Returns the size of the page. |
| getStart() | Returns the current start position from which iteration will start. |
| isEmpty() | Identifies if the model is empty. |
| setPageSize(Number) | Sets the size of the page. |
| setStart(Number) | Sets the current start position from which iteration will start. |
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
- DEFAULT_PAGE_SIZE: Number = 10
The default page size.
- MAX_PAGE_SIZE: Number = 2000
The maximum supported page size.
- PAGING_SIZE_PARAMETER: String = "sz"
The URL Parameter used for the page size.
- PAGING_START_PARAMETER: String = "start"
The URL parameter used for the start position.
- count: Number
(read-only) Returns the count of the number of items in the model.
- currentPage: Number
(read-only) Returns the index number of the current page. The page counting starts with 0. The method also works with a miss-aligned start. In that case the start is always treated as the start of a page.
- empty: Boolean
(read-only) Identifies if the model is empty.
- end: Number
(read-only) Returns the index of the last element on the current page.
- maxPage: Number
(read-only) Returns the maximum possible page number. Counting for pages starts with 0. The method also works with a miss-aligned start. In that case the returned number might be higher than ((count-1) / pageSize).
- pageCount: Number
(read-only) Returns the total page count. The method also works with a miss-aligned start. In that case the returned number might be higher than (count / pageSize).
- pageElements: Iterator
(read-only) Returns an iterator that can be used to iterate through the elements of the current page.
In case of a collection as the page models source, the method can be called multiple times. Each time a fresh iterator is returned.
In case of an iterator as the page models source, the method must be called only once. The method will always return the same iterator, which means the method amy return an exhausted iterator.
- pageSize: Number
Returns the size of the page.
- start: Number
Returns the current start position from which iteration will start.
- PagingModel(elements: Iterator, count: Number)
Constructs the PagingModel using the specified iterator and count value. Count must not be negative.
Note: A valid count must be provided. The PageModel class can not be used if the number of elements is unknown. Without knowning the number of elements it still would be possible to return the elements of a particular page, but it would be not possible to calculate data like the total number of pages or to construct an URL to jump to a particular page.
Parameters:
- elements - the iterator containing the model elements.
- count - the count of elements.
- PagingModel(elements: Collection)
Constructs the PagingModel using the specified collection.
Parameters:
- elements - the collection containing the model elements.
- static appendPageSize(url: URL, pageSize: Number): URL
Returns an URL containing the page size parameter appended to the specified url. The name of the page size parameter is 'sz' (see PAGE_SIZE_PARAMETER). The start position parameter is not appended to the returned URL.
Parameters:
- url - the URL to append the page size parameter to.
- pageSize - the page size
Returns:
- an URL that contains the page size parameter.
- appendPaging(url: URL): URL
Returns an URL by appending the current page start position and the current page size to the URL.
Parameters:
- url - the URL to append the current paging position to.
Returns:
- an URL containing the current paging position.
- appendPaging(url: URL, position: Number): URL
Returns an URL by appending the paging parameters for a desired page start position and the current page size to the specified url. The name of the page start position parameter is 'start' (see PAGING_START_PARAMETER) and the page size parameter is 'sz' (see PAGE_SIZE_PARAMETER).
Parameters:
- url - the URL to append the paging parameter to.
- position - the start position.
Returns:
- an URL that contains the paging parameters.
- getCount(): Number
Returns the count of the number of items in the model.
Returns:
- the count of the number of items in the model.
- getCurrentPage(): Number
Returns the index number of the current page. The page counting starts with 0. The method also works with a miss-aligned start. In that case the start is always treated as the start of a page.
Returns:
- the index number of the current page.
- getEnd(): Number
Returns the index of the last element on the current page.
Returns:
- the index of the last element on the current page.
- getMaxPage(): Number
Returns the maximum possible page number. Counting for pages starts with 0. The method also works with a miss-aligned start. In that case the returned number might be higher than ((count-1) / pageSize).
Returns:
- the maximum possible page number.
- getPageCount(): Number
Returns the total page count. The method also works with a miss-aligned start. In that case the returned number might be higher than (count / pageSize).
Returns:
- the total page count.
- getPageElements(): Iterator
Returns an iterator that can be used to iterate through the elements of the current page.
In case of a collection as the page models source, the method can be called multiple times. Each time a fresh iterator is returned.
In case of an iterator as the page models source, the method must be called only once. The method will always return the same iterator, which means the method amy return an exhausted iterator.
Returns:
- an iterator that you use to iterate through the elements of the current page.
- getPageSize(): Number
Returns the size of the page.
Returns:
- the size of the page.
- getStart(): Number
Returns the current start position from which iteration will start.
Returns:
- the current start position from which iteration will start.
- isEmpty(): Boolean
Identifies if the model is empty.
Returns:
- true if the model is empty, false otherwise.
- setPageSize(pageSize: Number): void
Sets the size of the page. The page size must be greater or equal to 1.
Parameters:
- pageSize - the size of the page.
- setStart(start: Number): void
Sets the current start position from which iteration will start.
Parameters:
- start - the current start position from which iteration will start.