API Docs for:
Show:

Y.PaginatorView Class

A View class extension to serve as a User Interface for the tracking of "pagination state" of a set of data. This PaginatorView was specifically designed to work with PaginatorModel serving as the "model" (in MVC parlance), although would work with any user-supplied model under conditions where similar attributes and attribute changes are mapped.

The PaginatorView was originally designed to function with DataTable (See Y.DataTable.Paginator) for managing the UI and page state of paginated tables, although it isn't necessarily limited to that application. This View responds to the model's attribute xxxxChange events and updates the UI accordingly.

The PaginatorView utilizes an HTML template concept, where certain replaceable tokens uniquely related to this view, in addition to all of the model's attributes, can be defined for positioning within the Paginator container.

Usage

// Setup a paginator view based on a data model for 500 items, paged at 50 per page ...
var pagView = new Y.PaginatorView(
   container:  '#myPagDIV',
   paginatorTemplate:  '#script-tmpl-mypag',
   model:  new Y.PaginatorModel({
       totalItems:     500,
       itemsPerPage:   50
       })
}).render();

View 'container'

The container attribute is the only REQUIRED attribute for this View, primarily because we need to know where to construct it positionally on the page.

This view has been designed such that the container setting can be either (a) an actual Y.Node instance OR (b) a DOM css selector ID ... assumed if the container setting is a {String} with the first character is '#'.

Paginator HTML Template

The "HTML template" for this PaginatorView is the guts of displaying the user interface. We refer to this as the "template" because it typically contains standard HTML but also includes "replacement tokens" identified by {your token here} curly braces.

A definition of HTML Template for the paginator can be achieved through several methods;

  • Including the HTML template as content within the original container DOM element ... template retrived via .getHTML()
  • Setting the paginatorTemplate attribute to either the template 'string', or giving a SCRIPT template DOM[id] or Y.Node
  • Doing neither of the above ... where the default template is used (from TMPL_PAGINATOR static property)

(Note: If for some reason it is desired to not have a "template" (because you are rendering one outside of this view), setting paginatorTemplate:'' will override the default.)

A noteworthy component of the "HTML template" includes the token {pageLinks}, which signifies where links generated by this view for each page selector are to be placed. In some instances (e.g. a Paginator Bar, with an INPUT[text] for page #) you may not desire to have every link generated ... (think of a paginator with hundreds of pages, thus hundreds of links).

A sub-template is used to generate the "{pageLinks}" content, please see attribute pageLinkTemplate for information.

For a listing of all recognized "replaceable tokens" that can be included in the template is shown on the render method API page.

Data Attribute

A key takeaway for using this View is that page links (i.e. actionable selectable elements, such as A, BUTTON, DIV, etc...) for a specific page use an HTML "data" attribute which defines the page associated with the link.

The data attribute used within the view is data-pglink, and can have a value setting of "first", "last", "prev", "next" or any numeric page number.

For example, the following are all valid page link identifiers;

<a href="#" data-pglink="last" title="Last Page">Last</a>
<button data-pglink="6" class="myBtn">Page 6</button>
<select><option data-pglink="19" value="19">Page 19 : Rows 9501 - 10000</option></select>

Connecting to "other" UI Elements / Widgets

This View can be restricted to situations where the use desires to construct their own unique pageLinkTemplate and create their own events attribute to set listeners.

For example, the PaginatorView's render event can be listened for to ensure that the paginator has been initialized and setup.

Additionally the pageChange event (of the view) can be listened for to do any updating to user-specified page links and or a supporting YUI Widget.

Please see the examples for a guide on how to achieve this.

Methods

_bindUI

() private

Setup listeners on this View, specifically on all UI elements and "most importantly", listen to "pageChange" on the underlying Model.

Returns:

this

_calcOffset

(
  • cpage
  • offset
)
Object private

Helper method to calculate offset either side of Selected Page link for abbreviated Page List.

Called by _processPageChange

Parameters:

  • cpage Integer

    Current page number

  • offset Integer

    Number of links both sides of page number to return for (usually 1)

Returns:

Object: containing left {Integer} and right {Integer} properties

_clickChangePage

(
  • e
)
private

Handler responding to a Page Selector "click" event. The clicked Node is reviewed for its data-pglink="" setting, and processed from that.

Changed page is then sent back to the Model, which reprocesses the paginator settings (i.e. indices) and fires a pageChange event.

Listener set in _bindUI

Parameters:

  • e EventFacade

_disablePageSelector

(
  • linkSel
  • visible
)
private

Method that toggles the visibility of Page Link selector fields based upon their data-pglink attribute setting.

Called by _processPageChange

Parameters:

  • linkSel Object
  • visible Object

_inputChangePage

(
  • e
)
private

Handler responding to INPUT[text] box page change.

Listener set in _bindUI

Parameters:

  • e EventFacade

_modelItemsChange

(
  • e
)
private

Handler responds to Model's itemsPerPageChange event

Listener set in _bindUI

Parameters:

  • e EventFacade

_modelPageChange

(
  • e
)
private

Handler responds to Model's pageChange event, if a valid page is set this listener fires off a page change request.

Listener set in _bindUI

Parameters:

  • e EventFacade

_modelStateChange

(
  • e
)
private

Handler responds to Model's itemsPerPageChange event, not really functional at present

Listener set in _bindUI

Parameters:

  • e EventFacade

_myClassName

(
  • String
)
private

Helper function, because I was too lazy to figure out how to get widget getClassName working

Parameters:

  • String Object

    variable number of strings, to be concatenated

Returns:

String

_processPageChange

(
  • cpage
)
private

Main handler that accomodates Page changes and updates visual cues for highlighting the selected page link and the active Page selector link list.

This method also fires the View's "pageChange" event.

NOTE: This method is private because page changes should be made by the user at the Model level (Model.set('page',...) and not using the _processPageChange method.

Parameters:

  • cpage Integer

_selectChangeRowOptions

(
  • e
)
private

Handler that responds to SELECT changes for no. of rows per page

Listener set in _bindUI

Parameters:

  • e EventFacade

_setModel

(
  • val
)
private

Setter for the "model" attribute, that for convenience also sets a public property to this View.

Parameters:

  • val Object

Returns:

:

_updatePageSelect

() private

Method that responds to changes in the SELECT box for "page"

_updateRPPSelect

() private

Method fired after the Paginator View is rendered, so that the SELECT[rowsPerPage] control can be updated

Listener set in _bindUI

destructor

() private

Default destructor method, cleans up the listeners that were created and cleans up the view contents.

initializer

() private

Initializer sets up classes and the initial container and HTML templating for this View.

Returns:

this

render

() public

Renders the current settings of the Paginator using the supplied HTML content from the for the paginator template and Y.Lang.sub for replacement of tokens and of Model attributes.

NOTE: The render method is not called on every page "click", but is called if the Model changes totalItems or itemsPerPage.

Recognized tokens:

Recognizeable tokens are supported, specifically as placeholders within the html template where generated content can be inserted and ultimately rendered in the view container.

Tokens replaced within this method include all of the PaginatorModel attributes;

{page}, {totalItems}, {itemsPerPage}, {lastPage}, {totalPages}, {itemIndexStart}, {itemIndexEnd}

Additionally, specific tokens intended for view HTML construction and recognized by PaginatorView are;

  • {pageLinks} : The placeholder within the html template where the View-generated page links will
    be inserted via a loop over all pages (DEFAULT: see TMPL_LINK)
  • {inputPage} : An INPUT[type=text] box which the view listens for change events on (Default: see TMPL_inputPage)
  • {selectRowsPerPage} : A SELECT type pulldown that will be populated with the pageOptions array
    of "Rows per Page" selections (Default: see TMPL_selectRPP)
  • {inputRowsPerPage} : An INPUT[type=text] box what will be listened to for changes to "Rows per Page" (Default: see TMPL_inputRPP)
  • {selectPage} (Not implemented at this time!)
  • {pageStartIndex} : Represents the starting index for a specific "page" (intended for use within pageLinkTemplate )
  • {pageEndIndex} : Represents the ending index for a specific "page" (intended for use within pageLinkTemplate )

And if that wasn't enough, the CSS class names supported by this view are also provided via tokens as; {pagClass}, {pageLinkClass}, {inputPageClass}, {selectRPPClass}, {selectPageClass}, * {inputRPPClass}

This method utilizes the Y.substitute tool (with recursion) for token replacement.

The container visibility is disabled during construction and insertion of DOM elements into the container node.

This method fires the render event, for View listeners.

Returns:

this

Properties

_pagHTML

Unknown protected

Placeholder property to store the initial container HTML for used later in the render method. This property is populated by the View initializer.

_subscr

Array protected

Holder for Event subscribers created by this View, saved so they can be cleaned up later.

Default: null

ATTRS

Object static

The default set of attributes which will be available for instances of this class

model

Y.PaginatorModel public

A public property, provided as a convenience property, equivalent to the "model" attribute.

Default: null

TMPL_inputPage

String

Default HTML template for the "Page" INPUT[text] control signified by the {inputPage} replacement token with the paginator template.

The DEFAULT setting is;

TMPL_inputRPP

String

Default HTML template for the "Rows Per Page" INPUT[text] control signified by the {inputRowsPerPage} replacement token within the paginator template.

The DEFAULT setting is;

TMPL_PAGINATOR

String

Default HTML content to be used as basis for Paginator. This default is only used if the paginatorTemplate attribute is unused OR the container does not contain the HTML template.

The paginator HTML content includes replacement tokens throughout.

The DEFAULT setting is;

First | Prev | {pageLinks} | Next | Last

TMPL_selectPage

String

Default HTML template for the Page SELECT box signified by the {selectPage} replacement token with the paginator template.

The DEFAULT setting is;

TMPL_selectRPP

String

Default HTML template for the Rows Per Page SELECT box signified by the {selectRowsPerPage} replacement toke within the paginator template.

The DEFAULT setting is;

Attributes

alwaysShowFirst

Boolean

Flag to indicate whether the first page link within the {pageLinks} template is to be displayed or not.
Specifically intended for abbreviated page link lists (See maxPageLinks attribute).

For Example;
If our paginator state currently has 9 pages, and the current page is 5, if alwaysShowLast:false and alwaysShowFirst:false the link list will resemble;
First | Prev | ... 4 5 6 ... | Next | Last

Likewise, with 'alwaysShowLast:true (and alwaysShowFirst:true) the link list will resemble;
First | Prev | 1 ... 4 5 6 ... 9 | Next | Last

Default: false

alwaysShowLast

Boolean

Flag to indicate whether the last page link within the {pageLinks} template is to be displayed or not.
Specifically intended for abbreviated page link lists (See maxPageLinks attribute).

See alowsShowFirst for an example.

Default: false

circular

Boolean

Flag indicating whether "circular" behavior of the Paginator View is desired. If true the paginator will stop "disabling" First|Previous or Next|Last toggling and will continue at either 1st page or last page selections. (i.e. when on last page, a next click will return to page 1)

Default: false

container

Node | String required

The container holder for the contents of this View. Can be entered either as a Y.Node instance or as a DOM "id" attribute (if prepended by "#").

Default: null

Example:

container: Y.one("#myDiv"), OR container: "#myDiv"

NOTE: If the container node contains HTML it will be used as the paginatorTemplate

linkListOffset

Integer

Setting that represents the number of links adjacent to the current page that should be displayed for instances where an abbreviated page link list is desired.
(See maxPageLinks and pageLinkFiller attributes).

For example, a setting of this attribute to 1, will result in 3 page links (current page plus 1 each side),
likewise a setting of 2, will results in 5 page links in the center of the paginator, etc.

Default: 1

model

Y.PaginatorModel

The base PaginatorModel that serves as data / change provider for this View.

Default: null

Example:

paginator:  new Y.PaginatorModel({
    itemsPerPage:  250
}),
OR
paginator:  myPagModel // where myPagModel is an instance previously created ...

pageLinkFiller

String

Setting the the ".. more" indicator to be used specifically for abbreviated page link lists.
(See maxPageLinks and linkListOffset attributes).

Default: '...'

pageLinkTemplate

String

Defines the HTML template to be used for each individual page within the Paginator. This can be used along with replacement tokens to create UI elements for each page link. The template is used to construct the {pageLinks} replacement token with the paginator body.

Recognized replacement tokens most appropriate to this attribute are {page}, {pageStartIndex} and {pageEndIndex}.

A few examples of this template are listed below;

Default: See TMPL_LINK static property

Example:

pageLinkTemplate: '{page}'

pageOptions

Array

An array that will be used to populate the rows per page SELECT box ( using string replacement "{selectRowsPerPage}" or class selector "yui3-pagview-select-rowsperpage" ).

Default: [ 10, 20, 'All' ]

paginatorTemplate

Node | String

A string that defines the Paginator HTML contents. Can either be entered as a {String} including replacement parameters or as a {Node} instance whose contents will be read via .getHTML() or a DOM "id" element (indicated by '#' in first character)

To disable creation of any template (in order to do your own replacements of the template), set this to ''.

Default: See TMPL_PAGINATOR static property

Example:

paginatorTemplate: '

FIRST
{pageLinks}
LAST
', paginatorTemplate: Y.one('#script-id-tmpl'), paginatorTemplate: Y.one('#script-id-tmpl').getHTML(), paginatorTemplate: '#script-id-tmpl', // where

selectPageFormat

String

Not implemented at this time.

Default: 'Page {page}'

Events

pageChange

Defined in gallery-js/paginator-view.js:1261

Available since 3.5.0

Fires after the _processPageChange method has updated the pagination state.

Event Payload:

  • state Object

    The PaginatorModel getAttrs() "state" after updating to the current page as an object.

render

Fires after the Paginator has been completely rendered.