API Docs for:
Show:

Y.PaginatorModel Class

A Model class extension to be used to track "pagination state" of a paged set of control elements. For example, can be used to track the pagination status of a DataTable where the user selects limited portions for display, against a larger data set.

The primary tools for maintaining "page state" is through the following attributes;

  • totalItems    Which represents the "Total count of items of interest" (See attribute totalItems )
  • itemsPerPage    Which represents the "Count of items on each page" (See attribute itemsPerPage )
  • page    The currently selected page, within all pages required that encompass the above two attributes (See attribute page )

Usage

// setup a paginator model for 500 'foo' items, paged at 50 per page ...
var pagModel = new Y.PaginatorModel({
   totalItems:     500,
   itemsPerPage:   50
});
pagModel.get('totalPages');  // returns 10

pagModel.set('page',3);
pagModel.getAttrs(['lastPage','page','itemIndexStart','itemIndexEnd']);
// returns ... { lastPage:1, page:3, itemIndexStart:100, itemIndexEnd:149 }

Methods

_changePage

(
  • e
)
private

Method responds to changes to "page" (via pageChange attribute change), validates the change compared to the current paginator settings, and stores the prior page in "lastPage".

If a page change is invalid (i.e. less than 1, non-numeric or greater than totalPages) the change is prevented.

Parameters:

  • e EventFacade

    page Attribute change event object

Returns:

Nothing

_getItemIndexEnd

() Integer private

Getter for returning the inclusive ending index for the current page

Returns:

Integer: Index of the last item on the current page

_getItemIndexStart

() Integer private

Getter for returning the start index for the current page

Returns:

Integer: Index of first item on the current page

_recalcPagnParams

() Boolean private

Method to calculate the current paginator settings, specifically the number of pages required, including a modulus calc for extra records requiring a final page.

This method resets the page to 1 (first page) upon completion.

Returns:

Boolean: Indicating the "success" or failure of recalculating the pagination state.

destructor

() private

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

initializer

() private

Creates self-listeners to recalculate paginator settings on items / itemsPerPage changes. Also sets listener to track 'lastPage' changes.

Returns:

this

Properties

_npages

Number protected

Placeholder for calculated # of pages required

_subscr

Array protected

Placeholder for Event subscribers created by this model, kept for detaching on destroy.

Attributes

itemIndexEnd

Integer

The index for the ending item on the current page within the pagination state.

This attribute is calculated on the fly in a getter method _getItemIndexEnd and should not be "set" by the user, as it will be disregarded.

Default: null

itemIndexStart

Integer

The index for the starting item on the current page within the pagination state.

This attribute is calculated on the fly in a getter method _getItemIndexStart and should not be "set" by the user, as it will be disregarded.

Default: null

itemsPerPage

Integer

Number of items per page for this paginator.

Default: null

lastPage

Integer

The last active page that was selected, this is populated by a pageChange listener on the Model.

Default: null

page

Integer

The current page selected for this paginator-model.

This is intended as the primary change parameter to be .set() by the user, for interacting with the Paginator Model.

Default: 1

totalItems

Integer

Total number of items used by this paginator-model.

Default: null

totalPages

Integer

The total number of pages required to complete this pagination state (based upon totalItems and itemsPerPage, specifically).

This attribute is set / maintained by the method _recalcPagnParams and shouldn't be set by the user.

Default: null

Events

itemsPerPageChange

Fires after the itemsPerPage attribute is changed

Event Payload:

  • e EventFacade

lastPageChange

Fires after the lastPage attribute is changed

Event Payload:

  • e EventFacade

pageChange

Fires after the page attribute is changed

Event Payload:

  • e EventFacade

totalItemsChange

Fires after the totalItems attribute is changed

Event Payload:

  • e EventFacade

totalPagesChange

Fires after the totalPages attribute is changed

Event Payload:

  • e EventFacade