JAVASCRIPT
Pagination elements
All samples are using Ink.requireModules
, please read how to use it at Ink.requireModules section
Method name | Description |
---|---|
new Pagination(selector, options) | Constructor |
.destroy() | Unregisters the component and removes its markup |
.getCurrent() | Gets the current page index. First page is 0. |
.getSize() | Gets the number of pages |
.hasNext() | Checks if it has next pages |
.hasNextPage() | Checks if it has a next set of pages |
.hasPrevious() | Checks if it has previous pages |
.hasPreviousPage() | Checks if it has a previous set of pages |
.isFirst() | Checks if it's at the first page |
.isLast() | Checks if it's on the last page |
.next([wrap]) | Navigates to next item |
.previous([wrap]) | Navigates to the previous item |
.setCurrent(nr, [isRelative], [wrap]) | Sets the current page. First page is 0. |
.setOnChange(onChange) | Allows you to subscribe to the onChange event |
.setSize(sz) | Sets the number of pages to sz |
.setSizeInItems(totalItems, itemsPerPage) | An alternative to setSize, to define the number of pages in the Paginator. |
selector
Selector or elementoptions
Optionsoptions.size
Number of pages.options.totalItemCount
Total number of items to displayoptions.itemsPerPage
Number of items per page.options.maxSize
If passed, only shows at most maxSize items. displays also first|prev page and next page|last buttonsoptions.start
Start page. defaults to 1options.sideButtons
trueWhether to show the first, last, previous, next, previousPage and lastPage buttons. Do not use together with maxSize.options.firstLabel
Text for the first page button. Defaults to 'First'.options.lastLabel
Text for the last page button. Defaults to 'Last'.options.previousLabel
Text for the previous button. Defaults to 'Previous'-options.nextLabel
Text for the next button. Defaults to 'Next'options.previousPageLabel
Text for the previous page button. Defaults to 'Previous {Items per page}'.options.nextPageLabel
Text for the next page button. Defaults to 'Next {Items per page}'.options.onChange
Callback to be called when a page changes. Called with `(thisPaginator, newPageNumber)`.options.hashParameter
Parameter to use on setHash. Defaults to 'page'.options.parentTag
HTML Tag used as the parent node.options.childTag
HTML Tag used as the child nodes.options.wrapperClass
CSS Class used in the wrapper elementoptions.paginationClass
CSS Class used in the pagination elementoptions.activeClass
CSS Class used to mark page as activeoptions.disabledClass
CSS Class used to mark page as disabledoptions.hideClass
CSS Class used to hide elementsoptions.previousClass
CSS Class used in the previous elementoptions.previousPageClass
CSS Class used in the previous page elementoptions.nextClass
CSS Class used in the next elementoptions.nextPageClass
CSS Class used in the next page elementoptions.numberFormatter
Number formatter function. Receives a 0-indexed page number, and the page count. Returns the text for the numbered page button.options.autoWrap
falseWhether to navigate to first page when clicking next in last page or vice-versa.Pagination just takes an element with the markup described in UI Elements: Pagination and creates the page numbers automatically.
It isn't very useful in and of itself, but some other UI components in Ink, such as the Table and the Carousel, use it internally.
Demo
Code
You can use the maxSize
option to limit the amount of pages shown.
Demo
Code
To configure your Pagination visually, refer to the documentation in UI Elements: Pagination
Code
Unregisters the component and removes its markup
Gets the current page index. First page is 0.
Gets the number of pages
Checks if it has next pages
Checks if it has a next set of pages
Checks if it has previous pages
Checks if it has a previous set of pages
Checks if it's at the first page
Checks if it's on the last page
Navigates to next item
wrap
falseSet this to true if you want to go to the first item when going after the last item.Navigates to the previous item
wrap
falseSet this to true if you want to go to the last item when going before the first item.Sets the current page. First page is 0.
nr
Sets the current page to given number.isRelative
falseIf you set this to `true`, the function will perform a relative change. (example: setCurrent(1) will move to the next page, while setCurrent(-1) will move to the previous page)wrap
falseSet this to true to wrap to the first page when moving past the last, and to wrap to the last page when moving before the first one.Allows you to subscribe to the onChange event
onChange
Callback called with `(thisPaginator, newPageNumber)`.Sets the number of pages to sz
sz
number of pagesAn alternative to setSize, to define the number of pages in the Paginator.
If you don't know how many pages you want, but know the amount of items you have and how many of them you want on each page, use this.
totalItems
Total number of itemsitemsPerPage
Items per page