The Paginator utility allows you to display an item or a group of items depending on the number of items you wish to display at one time.
Paginator's primary functionality is contained in paginator-core
and is mixed
into paginator
to allow paginator
to have extra functionality added to it
while leaving the core functionality untouched. This allows paginator-core
to
remain available for use later on or used in isolation if it is the only piece
you need.
Due to the vast number of interfaces a paginator could possibly consist of,
Paginator
does not contain any ready to use UIs. However, Paginator
is
ready to be used in any Based-based, module such as a Widget, by extending your
desired class and mixing in Paginator
. This is displayed in the following
example:
YUI().use('paginator-url', 'widget', function (Y){
var MyPaginator = Y.Base.create('my-paginator', Y.Widget, [Y.Paginator], {
renderUI: function () {
var numbers = '',
i, numberOfPages = this.get('totalPages');
for (i = 1; i <= numberOfPages; i++) {
// use paginator-url's formatUrl method
numbers += '<a href="' + this.formatUrl(i) + '">' + i + '</a>';
}
this.get('boundingBox').append(numbers);
},
bindUI: function () {
this.get('boundingBox').delegate('click', function (e) {
// let's not go to the page, just update internally
e.preventDefault();
this.set('page', parseInt(e.currentTarget.getContent(), 10));
}, 'a', this);
this.after('pageChange', function (e) {
// mark the link selected when it's the page being displayed
var bb = this.get('boundingBox'),
activeClass = 'selected';
bb.all('a').removeClass(activeClass).item(e.newVal).addClass(activeClass);
});
}
});
var myPg = new MyPaginator({
totalItems: 100,
pageUrl: '?pg={page}'
});
myPg.render();
});
_getTotalPagesFn
Returns the total number of pages based on the total number of items provided and the number of items per page
Total number of pages based on total number of items and items per page or one if itemsPerPage is less than one
hasNextPage
Returns True if there is a next page in the set.
If totalItems isn't set, assume there is always next page.
true
if there is a next page, false
otherwise.
hasPrevPage
Returns True if there is a previous page in the set.
true
if there is a previous page, false
otherwise.
nextPage
Sets the page to the next page in the set, if there is a next page.
prevPage
Sets the page to the previous page in the set, if there is a previous page.
itemsPerPage
Maximum number of items per page. A value of negative one (-1) indicates all items on one page.
Default: 10
itemsPerPageChange
Fires when the value for the configuration attribute itemsPerPage
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
e
EventFacade
page
Current page count. First page is 1.
Default: 1
pageChange
Fires when the value for the configuration attribute page
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
e
EventFacade
totalItems
Total number of items in all pages.
Default: 0
totalItemsChange
Fires when the value for the configuration attribute totalItems
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
e
EventFacade
totalPages
Total number of pages to display
totalPagesChange
Fires when the value for the configuration attribute totalPages
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
e
EventFacade