-
Notifications
You must be signed in to change notification settings - Fork 0
Paginator
Aferz edited this page Feb 3, 2016
·
1 revision
Paginator has this attributes that are self-explanatory:
- totalRecords
- recordsPerPage
- totalPages
- pages
To get a better experience Vivaz provides a good wraper around pages with several methods for your personal use. Let's use this data:
var data = [
{
id: 1,
name: 'Isaac',
birthdate: '1643-01-04',
swag: 99,
study_fields: [ 'Gravity', 'Light', 'Motion' ],
hasPet: undefined
},
{
id: 2,
name: 'Michael',
year: '1791-09-22',
swag: 87,
study_fields: [ 'Electromagnetism', 'Electrochemistry' ],
hasPet: true
},
{
id: 3,
name: 'Erwin',
year: '1887-08-12',
swag: 93,
study_fields: [ 'Quantum Mechanics' ],
hasPet: null
},
];
It gives you the records of the current page.
var paginator = Vivaz( data ).paginate( 2 );
var result = paginator.current();
// paginator.currentIndex = 1
// [ { id: 1, name: 'Isaac', ... }, { id: 2, name: 'Michael', ... } ]
It gives you the records of the next page, moving the pointer to that page.
var paginator = Vivaz( data ).paginate( 2 );
var result = paginator.next();
// paginator.currentIndex = 2
// [ { id: 3, name: 'Erwin', ... } ]
It gives you the records of the previous page, moving the pointer to that page.
var paginator = Vivaz( data ).paginate( 2 );
var result = paginator.previous();
// Gives you the previous results
Go to page given as argument.
var paginator = Vivaz( data ).paginate( 2 );
var result = paginator.page( 2 );
// Gives you the results of page 2